bloritsch    2002/08/08 22:32:03

  Modified:    event/src/java/org/apache/excalibur/event/command
                        AbstractThreadManager.java
               event/src/java/org/apache/excalibur/mpool FixedSizePool.java
               event/src/java/org/apache/excalibur/thread/impl
                        DefaultThreadPool.java
               event/src/test/org/apache/excalibur/event/command/test
                        TPCThreadManagerTestCase.java
  Log:
  update blocking code
  
  Revision  Changes    Path
  1.5       +26 -4     
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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- AbstractThreadManager.java        8 Aug 2002 00:36:26 -0000       1.4
  +++ AbstractThreadManager.java        9 Aug 2002 05:32:03 -0000       1.5
  @@ -49,6 +49,7 @@
   */
   package org.apache.excalibur.event.command;
   
  +import java.util.LinkedList;
   import java.util.HashMap;
   import java.util.Iterator;
   
  @@ -73,11 +74,12 @@
   {
       private final Mutex m_mutex = new Mutex();
       private final HashMap m_pipelines = new HashMap();
  +    private final LinkedList m_controls = new LinkedList();
       private ThreadPool m_threadPool;
       private ThreadControl m_threadControl;
  -    private boolean m_done = false;
  +    private volatile boolean m_done = false;
       private long m_sleepTime = 1000L;
  -    private boolean m_initialized = false;
  +    private volatile boolean m_initialized = false;
   
       protected boolean isInitialized()
       {
  @@ -202,9 +204,17 @@
               try
               {
                   m_done = true;
  +                m_threadControl.join( 1000 );
  +
  +                Iterator it = m_controls.iterator();
  +
  +                while( it.hasNext() )
  +                {
  +                    ( (ThreadControl) it.next() ).join( 1000 );
  +                }
  +
                   m_pipelines.clear();
   
  -                m_threadControl.join( 1000 );
               }
               finally
               {
  @@ -240,7 +250,7 @@
                       {
                           try
                           {
  -                            m_threadPool.execute( ( PipelineRunner ) i.next() );
  +                            m_controls.add(m_threadPool.execute( ( PipelineRunner ) 
i.next() ));
                           }
                           catch( IllegalStateException e )
                           {
  @@ -264,6 +274,18 @@
                   }
   
                   Thread.sleep( m_sleepTime );
  +
  +                m_mutex.acquire();
  +
  +                Iterator it = m_controls.iterator();
  +
  +                while ( it.hasNext() )
  +                {
  +                    ThreadControl control = (ThreadControl) it.next();
  +                    if (control.isFinished()) it.remove();
  +                }
  +
  +                m_mutex.release();
               }
           }
           catch( InterruptedException e )
  
  
  
  1.3       +9 -7      
jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/mpool/FixedSizePool.java
  
  Index: FixedSizePool.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/mpool/FixedSizePool.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- FixedSizePool.java        8 Aug 2002 00:57:25 -0000       1.2
  +++ FixedSizePool.java        9 Aug 2002 05:32:03 -0000       1.3
  @@ -98,7 +98,8 @@
   
           Object object = null;
   
  -        long end = System.currentTimeMillis() + m_timeout;
  +        long start = System.currentTimeMillis();
  +        long end = start + m_timeout;
   
           while ( null == object && System.currentTimeMillis() < end)
           {
  @@ -110,13 +111,14 @@
                       {
                           m_buffer.wait( m_timeout );
                       }
  -                    catch (Exception e) {}
  +                    catch (InterruptedException e) {}
  +                }
  +                else
  +                {
  +                    object = m_buffer.remove();
                   }
  -
  -                object = m_buffer.remove();
               }
           }
  -
           return object;
       }
   
  @@ -138,7 +140,7 @@
               synchronized( m_buffer )
               {
                   m_buffer.add( object );
  -                m_buffer.notify();
  +                m_buffer.notifyAll();
               }
           }
       }
  
  
  
  1.2       +0 -1      
jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/thread/impl/DefaultThreadPool.java
  
  Index: DefaultThreadPool.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/thread/impl/DefaultThreadPool.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DefaultThreadPool.java    8 Aug 2002 00:36:26 -0000       1.1
  +++ DefaultThreadPool.java    9 Aug 2002 05:32:03 -0000       1.2
  @@ -113,7 +113,6 @@
       public Object newInstance()
       {
           final String name = getName() + " Worker #" + m_level++;
  -
           ThreadContext context = null;
           if( null != m_context )
           {
  
  
  
  1.5       +4 -4      
jakarta-avalon-excalibur/event/src/test/org/apache/excalibur/event/command/test/TPCThreadManagerTestCase.java
  
  Index: TPCThreadManagerTestCase.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-avalon-excalibur/event/src/test/org/apache/excalibur/event/command/test/TPCThreadManagerTestCase.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TPCThreadManagerTestCase.java     7 Aug 2002 23:08:26 -0000       1.4
  +++ TPCThreadManagerTestCase.java     9 Aug 2002 05:32:03 -0000       1.5
  @@ -81,11 +81,10 @@
       // number of times the handler should be called
       private final static int MINIMAL_NUMBER_INVOCATIONS = 2;
   
  -    private Parameters createParameters( int processors, int threadsPerProcessor, 
long sleep )
  +    private Parameters createParameters( int threadsPerProcessor, long sleep )
       {
           final Parameters parameters = new Parameters();
   
  -        parameters.setParameter( "processors", String.valueOf( processors ) );
           parameters.setParameter( "threads-per-processor", String.valueOf( 
threadsPerProcessor ) );
           parameters.setParameter( "sleep-time", String.valueOf( sleep ) );
   
  @@ -107,7 +106,7 @@
           // fail quickly
           final TPCThreadManager threadManager = new TPCThreadManager();
   
  -        threadManager.parameterize( createParameters( 1, 1, 0 ) );
  +        threadManager.parameterize( createParameters( 1, 0 ) );
           threadManager.initialize();
   
           // an obviously syncronized component
  @@ -118,7 +117,7 @@
           threadManager.register( new Pipeline( result, errorOut ) );
   
           // sleeps for 1 more scheduling timeout to surely go over limit
  -        Thread.sleep( SCHEDULING_TIMEOUT * ( MINIMAL_NUMBER_INVOCATIONS + 1 ) );
  +        Thread.sleep( SCHEDULING_TIMEOUT * ( MINIMAL_NUMBER_INVOCATIONS + 1) );
   
           int numberCalls = result.length();
   
  @@ -189,6 +188,7 @@
                   m_queue.enqueue( new QueueElement()
                   {
                   } );
  +                System.out.println("added element");
               }
               catch( Exception e )
               {
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to