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 19:26:05 UTC

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

bloritsch    2003/01/27 10:26:04

  Modified:    event    default.properties
               event/src/java/org/apache/excalibur/event/command
                        AbstractThreadManager.java TPCThreadManager.java
  Log:
  better mutex and exception handling
  
  Revision  Changes    Path
  1.31      +1 -1      jakarta-avalon-excalibur/event/default.properties
  
  Index: default.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/event/default.properties,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- default.properties	27 Jan 2003 07:11:06 -0000	1.30
  +++ default.properties	27 Jan 2003 18:26:02 -0000	1.31
  @@ -19,7 +19,7 @@
   # ----- 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.jar
  +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.14      +66 -39    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.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- AbstractThreadManager.java	23 Jan 2003 21:26:51 -0000	1.13
  +++ AbstractThreadManager.java	27 Jan 2003 18:26:04 -0000	1.14
  @@ -202,28 +202,32 @@
           {
               m_mutex.acquire();
   
  -            try
  -            {
  -                m_pipelines.remove( pipeline );
  +            m_pipelines.remove( pipeline );
   
  -                if( m_pipelines.isEmpty() )
  -                {
  -                    m_done = true;
  -                }
  -            }
  -            finally
  +            if( m_pipelines.isEmpty() )
               {
  -                m_mutex.release();
  +                m_done = true;
               }
  +        }
  +        catch (InterruptedException ie)
  +        {
  +            getLogger().warn( "deregister(" + pipeline + ") threw an InterruptedException", ie );
  +        }
  +        finally
  +        {
  +            m_mutex.release();
  +        }
   
  -            if( m_done )
  +        if( m_done )
  +        {
  +            try
               {
                   m_threadControl.join( 1000 );
               }
  -        }
  -        catch( InterruptedException ie )
  -        {
  -            // ignore for now
  +            catch(InterruptedException ie)
  +            {
  +                getLogger().warn( "deregister(" + pipeline + ") threw an InterruptedException", ie );
  +            }
           }
       }
   
  @@ -242,37 +246,51 @@
           {
               // Aquire mutex to clear pipelines and set the m_done flag
               m_mutex.acquire();
  -            try
  +
  +            m_pipelines.clear();
  +
  +            m_done = true;
  +            Iterator it = m_controls.iterator();
  +
  +            while( it.hasNext() )
               {
  -                m_done = true;
  -                Iterator it = m_controls.iterator();
  +                ThreadControl tc = (ThreadControl) it.next();
   
  -                while( it.hasNext() )
  +                try
                   {
  -                    ThreadControl tc = (ThreadControl) it.next();
  -
  -                    try
  -                    {
  -                        tc.join( 1000 );
  -                    }
  -                    catch (Exception e)
  -                    {
  -                        tc.interrupt();
  -                    }
  +                    tc.join( 1000 );
  +                }
  +                catch (InterruptedException e)
  +                {
  +                    tc.interrupt();
                   }
  -                m_pipelines.clear();
   
  +                getLogger().debug("disposed of another ThreadControl");
               }
  -            finally
  +
  +            if ( ! m_pipelines.isEmpty() )
               {
  -                //  C.K. We must release the mutex to give the manager thread a chance to terminate.
  -                m_mutex.release();
  +                throw new IllegalStateException("We still have pipelines, but no runners are available!");
               }
  +
  +        }
  +        catch (InterruptedException ie)
  +        {
  +            getLogger().warn( "deregisterAl() threw an InterruptedException", ie );
  +        }
  +        finally
  +        {
  +            //  C.K. We must release the mutex to give the manager thread a chance to terminate.
  +            m_mutex.release();
  +        }
  +
  +        try
  +        {
               m_threadControl.join( 1000 );
           }
  -        catch( InterruptedException ie )
  +        catch (InterruptedException ie)
           {
  -            // ignore for now
  +            getLogger().warn( "deregisterAl() threw an InterruptedException", ie );
           }
       }
   
  @@ -284,6 +302,8 @@
       {
           deregisterAll();
   
  +        doDispose();
  +
           if( m_threadControl != null && !m_threadControl.isFinished() )
           {
               if( getLogger().isErrorEnabled() )
  @@ -295,6 +315,8 @@
           m_threadControl = null;
       }
   
  +    protected void doDispose() {} // default impl to work with released code
  +
       /**
        * Return the thread controlls of all active threads
        * (excluding the ThreadManager management thread)
  @@ -326,10 +348,10 @@
           {
               while( !m_done )
               {
  -                m_mutex.acquire();
  -
                   try
                   {
  +                    m_mutex.acquire();
  +
                       Iterator i = m_pipelines.values().iterator();
   
                       while( i.hasNext() )
  @@ -357,6 +379,11 @@
                                                         + "per processor", e );
                                   }
                               }
  +
  +                            if (getLogger().isDebugEnabled())
  +                            {
  +                                getLogger().debug( "Waiting on " + control );
  +                            }
                           }
   
                           m_controls.add( control );
  @@ -369,10 +396,10 @@
   
                   Thread.sleep( m_sleepTime );
   
  -                m_mutex.acquire();
  -
                   try
                   {
  +                    m_mutex.acquire();
  +
                       Iterator it = m_controls.iterator();
   
                       while( it.hasNext() )
  
  
  
  1.34      +1 -3      jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/event/command/TPCThreadManager.java
  
  Index: TPCThreadManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/event/command/TPCThreadManager.java,v
  retrieving revision 1.33
  retrieving revision 1.34
  diff -u -r1.33 -r1.34
  --- TPCThreadManager.java	4 Dec 2002 02:52:37 -0000	1.33
  +++ TPCThreadManager.java	27 Jan 2003 18:26:04 -0000	1.34
  @@ -145,10 +145,8 @@
           super.initialize();
       }
   
  -    public final void dispose()
  +    protected final void doDispose()
       {
  -        super.dispose();
  -
           // We should dispose all active threads
           final ThreadControl[] threads = getThreadControls();
   
  
  
  

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