You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by bl...@apache.org on 2003/01/27 22:00:34 UTC

cvs commit: jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/event/command AbstractThreadManager.java TPSPThreadManager.java EventThreadPool.java

bloritsch    2003/01/27 13:00:34

  Modified:    event    build.xml default.properties
               event/src/java/org/apache/excalibur/event/command
                        AbstractThreadManager.java TPSPThreadManager.java
  Removed:     event/src/java/org/apache/excalibur/event/command
                        EventThreadPool.java
  Log:
  completely divorce excalibur.thread from Event
  
  Revision  Changes    Path
  1.41      +0 -2      jakarta-avalon-excalibur/event/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/event/build.xml,v
  retrieving revision 1.40
  retrieving revision 1.41
  diff -u -r1.40 -r1.41
  --- build.xml	27 Jan 2003 07:11:06 -0000	1.40
  +++ build.xml	27 Jan 2003 21:00:34 -0000	1.41
  @@ -14,7 +14,6 @@
           <pathelement location="${commons-collections.jar}"/>
           <pathelement location="${build.classes}"/>
           <pathelement location="${util.concurrent.jar}"/>
  -        <pathelement location="${excalibur-thread.jar}"/>
           <pathelement location="${excalibur-scratchpad.jar}"/>
           <pathelement location="${avalon-framework.jar}"/>
           <pathelement location="${checkstyle.jar}"/>
  @@ -45,7 +44,6 @@
       <target name="dependencies" description="Check dependencies" unless="skip.dependencies">
           <ant antfile="${depchecker.prefix}/depchecker.xml" target="checkCommon"/>
           <ant antfile="${depchecker.prefix}/depchecker.xml" target="checkFramework"/>
  -        <ant antfile="${depchecker.prefix}/depchecker.xml" target="checkThread"/>
       </target>
   
       <target name="dependencies-test" depends="dist-jar, dependencies"
  
  
  
  1.32      +0 -5      jakarta-avalon-excalibur/event/default.properties
  
  Index: default.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/event/default.properties,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- default.properties	27 Jan 2003 18:26:02 -0000	1.31
  +++ default.properties	27 Jan 2003 21:00:34 -0000	1.32
  @@ -16,11 +16,6 @@
   #                REQUIRED LIBRARIES
   # --------------------------------------------------
   
  -# ----- Excalibur thread, version 1.0 or later -----
  -excalibur-thread.home=${basedir}/../thread
  -excalibur-thread.lib=${excalibur-thread.home}/build/lib
  -excalibur-thread.jar=${excalibur-thread.lib}/excalibur-thread-1.1.1.jar
  -
   # ----- Commons Collections, version 2.1 or later -----
   commons-collections.jar=lib/commons-collections-2.1.jar
   
  
  
  
  1.16      +11 -7     jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/event/command/AbstractThreadManager.java
  
  Index: AbstractThreadManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/event/command/AbstractThreadManager.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- AbstractThreadManager.java	27 Jan 2003 19:54:54 -0000	1.15
  +++ AbstractThreadManager.java	27 Jan 2003 21:00:34 -0000	1.16
  @@ -226,6 +226,7 @@
        */
       public void dispose()
       {
  +        m_done = true;
           deregisterAll();
   
           doDispose();
  @@ -260,13 +261,16 @@
                   }
               }
   
  -            try
  +            if ( !m_done )
               {
  -                Thread.sleep( m_sleepTime );
  -            }
  -            catch( InterruptedException e )
  -            {
  -                Thread.interrupted();
  +                try
  +                {
  +                    Thread.sleep( m_sleepTime );
  +                }
  +                catch( InterruptedException e )
  +                {
  +                    Thread.interrupted();
  +                }
               }
           }
       }
  @@ -306,7 +310,7 @@
                   {
                       handler.handleEvents( sources[i].dequeueAll() );
                   }
  -                catch( RuntimeException e )
  +                catch( Exception e )
                   {
                       // We want to catch this, because this is the only
                       // place where exceptions happening in this thread
  
  
  
  1.19      +35 -96    jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/event/command/TPSPThreadManager.java
  
  Index: TPSPThreadManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/event/command/TPSPThreadManager.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- TPSPThreadManager.java	2 Oct 2002 17:49:20 -0000	1.18
  +++ TPSPThreadManager.java	27 Jan 2003 21:00:34 -0000	1.19
  @@ -49,9 +49,9 @@
   */
   package org.apache.excalibur.event.command;
   
  -import java.util.HashMap;
   import java.util.Iterator;
  -import EDU.oswego.cs.dl.util.concurrent.ReentrantLock;
  +import EDU.oswego.cs.dl.util.concurrent.PooledExecutor;
  +import org.apache.commons.collections.StaticBucketMap;
   import org.apache.excalibur.event.EventHandler;
   import org.apache.excalibur.event.Source;
   import org.apache.excalibur.thread.ThreadControl;
  @@ -68,11 +68,10 @@
   public final class TPSPThreadManager implements Runnable, ThreadManager
   {
       private final ThreadPool m_threadPool;
  -    private final ReentrantLock m_mutex = new ReentrantLock();
  -    private final HashMap m_pipelines = new HashMap();
  -    private ThreadControl m_threadControl;
  -    private boolean m_done = false;
  +    private final StaticBucketMap m_pipelines = new StaticBucketMap();
  +    private volatile boolean m_done = false;
       private final long m_sleepTime;
  +    private int m_threadsPerPool = 2;
   
       /**
        * The default constructor assumes there is a system property named "os.arch.cpus"
  @@ -84,47 +83,28 @@
       public TPSPThreadManager()
           throws Exception
       {
  -        this( 1, 1, 1000 );
  +        this( 2, 1000 );
       }
   
       /**
        * Constructor provides a specified number of threads per processor.  If
        * either value is less then one, then the value is rewritten as one.
        *
  -     * @param numProcessors        The number of processors in the machine
  -     * @param threadsPerProcessor  The number of threads to allocate for each processor
  +     * @param maxThreadPerPool     The number of processors in the machine
        * @param sleepTime            The number of milliseconds to wait between cycles
        *
        * @throws Exception when there is a problem creating the ThreadManager
        */
  -    public TPSPThreadManager( int numProcessors, int threadsPerProcessor, long sleepTime )
  +    public TPSPThreadManager( int maxThreadPerPool, long sleepTime )
           throws Exception
       {
  -        this( numProcessors, threadsPerProcessor, sleepTime, 1000L );
  -    }
  -
  -    /**
  -     * Constructor provides a specified number of threads per processor.  If
  -     * either value is less then one, then the value is rewritten as one.
  -     *
  -     * @param numProcessors        The number of processors in the machine
  -     * @param threadsPerProcessor  The number of threads to allocate for each processor
  -     * @param sleepTime            The number of milliseconds to wait between cycles
  -     * @param timeOut              The number of milliseconds to use as a "timeout" parameter
  -     *
  -     * @throws Exception when there is a problem creating the ThreadManager
  -     */
  -    public TPSPThreadManager( int numProcessors, int threadsPerProcessor, long sleepTime, long timeOut )
  -        throws Exception
  -    {
  -        int processors = Math.max( numProcessors, 1 );
  -        int threads = Math.max( threadsPerProcessor, 1 );
  -
  -        m_threadPool = new EventThreadPool( "TPCThreadManager",
  -                                            ( processors * threads ) + 1, (int)timeOut );
  +        m_threadsPerPool = maxThreadPerPool;
   
           m_sleepTime = sleepTime;
  -        m_threadControl = m_threadPool.execute( this );
  +
  +        Thread runner = new Thread(this);
  +        runner.setDaemon(true);
  +        runner.start();
       }
   
       /**
  @@ -134,24 +114,13 @@
        */
       public void register( EventPipeline pipeline )
       {
  -        try
  -        {
  -            m_mutex.acquire();
  -
  -            m_pipelines.put( pipeline, new PipelineRunner( pipeline ) );
  +        m_pipelines.put( pipeline, new PipelineRunner( pipeline ) );
   
  -            if( m_done )
  -            {
  -                m_threadControl = m_threadPool.execute( this );
  -            }
  -        }
  -        catch( InterruptedException ie )
  +        if( m_done )
           {
  -            // ignore for now
  -        }
  -        finally
  -        {
  -            m_mutex.release();
  +            Thread runner = new Thread(this);
  +            runner.setDaemon(true);
  +            runner.start();
           }
       }
   
  @@ -162,25 +131,11 @@
        */
       public void deregister( EventPipeline pipeline )
       {
  -        try
  -        {
  -            m_mutex.acquire();
  +        m_pipelines.remove( pipeline );
   
  -            m_pipelines.remove( pipeline );
  -
  -            if( m_pipelines.isEmpty() )
  -            {
  -                m_done = true;
  -                m_threadControl.join( 1000 );
  -            }
  -        }
  -        catch( InterruptedException ie )
  -        {
  -            // ignore for now
  -        }
  -        finally
  +        if( m_pipelines.isEmpty() )
           {
  -            m_mutex.release();
  +            m_done = true;
           }
       }
   
  @@ -189,23 +144,8 @@
        */
       public void deregisterAll()
       {
  -        try
  -        {
  -            m_mutex.acquire();
  -
  -            m_done = true;
  -            m_pipelines.clear();
  -
  -            m_threadControl.join( 1000 );
  -        }
  -        catch( InterruptedException ie )
  -        {
  -            // ignore for now
  -        }
  -        finally
  -        {
  -            m_mutex.release();
  -        }
  +        m_done = true;
  +        m_pipelines.clear();
       }
   
       public void run()
  @@ -214,31 +154,30 @@
           {
               try
               {
  -                m_mutex.acquire();
  -
                   Iterator i = m_pipelines.values().iterator();
   
                   while( i.hasNext() )
                   {
  -                    m_threadPool.execute( (PipelineRunner)i.next() );
  +                    Thread runner = new Thread( (PipelineRunner)i.next() );
  +                    runner.setDaemon(true);
  +                    runner.start();
                   }
               }
               catch( InterruptedException ie )
               {
                   // ignore for now
               }
  -            finally
  -            {
  -                m_mutex.release();
  -            }
   
  -            try
  -            {
  -                Thread.sleep( m_sleepTime );
  -            }
  -            catch( InterruptedException ie )
  +            if (! m_done)
               {
  -                // ignore and continue processing
  +                try
  +                {
  +                    Thread.sleep( m_sleepTime );
  +                }
  +                catch( InterruptedException ie )
  +                {
  +                    // ignore and continue processing
  +                }
               }
           }
       }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>