leif        02/02/20 01:44:25

  Modified:    src/java/org/apache/avalon/excalibur/component
                        ComponentHandler.java DefaultComponentFactory.java
  Log:
  Fix some synchronization problems with patch.
  
  Revision  Changes    Path
  1.6       +21 -4     
jakarta-avalon-excalibur/src/java/org/apache/avalon/excalibur/component/ComponentHandler.java
  
  Index: ComponentHandler.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-avalon-excalibur/src/java/org/apache/avalon/excalibur/component/ComponentHandler.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ComponentHandler.java     20 Feb 2002 06:26:42 -0000      1.5
  +++ ComponentHandler.java     20 Feb 2002 09:44:25 -0000      1.6
  @@ -25,12 +25,14 @@
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Ryan Shaw</a>
  - * @version CVS $Revision: 1.5 $ $Date: 2002/02/20 06:26:42 $
  + * @author <a href="mailto:[EMAIL PROTECTED]">Leif Mortenson</a>
  + * @version CVS $Revision: 1.6 $ $Date: 2002/02/20 09:44:25 $
    * @since 4.0
    */
   public abstract class ComponentHandler extends AbstractLoggable
                                          implements Initializable, Disposable {
   
  +    private Object m_referenceSemaphore = new Object();
       private int m_references = 0;
   
       public static ComponentHandler getComponentHandler(
  @@ -137,7 +139,9 @@
       {
           Component component = doGet();
           
  -        m_references++;
  +        synchronized(m_referenceSemaphore) {
  +            m_references++;
  +        }
   
           return component;
       }
  @@ -155,9 +159,22 @@
        */
       public void put(Component component) throws Exception
       {
  -        doPut( component );
  +        // The reference count must be decremented before any calls to doPut.
  +        //  If there is another thread blocking, then this thread could stay 
deep inside
  +        //  doPut for an undetermined amount of time until the thread 
scheduler gives it
  +        //  some cycles again.  (It happened).  All ComponentHandler state 
must therefor
  +        //  reflect the thread having left this method before the call to 
doPut to avoid
  +        //  warning messages from the dispose() cycle if that takes place 
before this
  +        //  thread has a chance to continue.
  +        synchronized(m_referenceSemaphore) {
  +            m_references--;
  +        }
           
  -        m_references--;
  +        try {
  +            doPut( component );
  +        } catch (Throwable t) {
  +            t.printStackTrace();
  +        }
       }
   
       /**
  
  
  
  1.12      +20 -5     
jakarta-avalon-excalibur/src/java/org/apache/avalon/excalibur/component/DefaultComponentFactory.java
  
  Index: DefaultComponentFactory.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-avalon-excalibur/src/java/org/apache/avalon/excalibur/component/DefaultComponentFactory.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- DefaultComponentFactory.java      20 Feb 2002 06:26:42 -0000      1.11
  +++ DefaultComponentFactory.java      20 Feb 2002 09:44:25 -0000      1.12
  @@ -42,7 +42,7 @@
    * @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Paul Russell</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Ryan Shaw</a>
  - * @version CVS $Revision: 1.11 $ $Date: 2002/02/20 06:26:42 $
  + * @version CVS $Revision: 1.12 $ $Date: 2002/02/20 09:44:25 $
    * @since 4.0
    */
   public class DefaultComponentFactory
  @@ -290,7 +290,7 @@
           {
               Component component = m_realManager.lookup( role ); 
               
  -            m_unreleased.add( component );
  +            addUnreleased( component );
               
               return component; 
           }
  @@ -302,16 +302,31 @@
           
           public void release( Component component ) 
           {
  -            m_unreleased.remove( component );
  +            removeUnreleased( component );
               
               m_realManager.release( component );
           }
           
  +        private synchronized void addUnreleased( Component component )
  +        {
  +            m_unreleased.add( component );
  +        }
  +
  +        private synchronized void removeUnreleased( Component component )
  +        {
  +            m_unreleased.remove( component );
  +        }
  +        
  +
           private void releaseAll()
           {
  -            Component[] unreleased = new Component[ m_unreleased.size() ];
  +            Component[] unreleased;
               
  -            m_unreleased.toArray( unreleased );
  +            synchronized ( this )
  +            {
  +                unreleased = new Component[ m_unreleased.size() ];
  +                m_unreleased.toArray( unreleased );
  +            }
               
               for( int i = 0; i < unreleased.length; i++ )
               {
  
  
  

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

Reply via email to