bloritsch    01/03/01 12:12:24

  Modified:    src/org/apache/cocoon/util Tag: xml-cocoon2
                        ComponentPool.java
  Log:
  Added more pool instances.  I need to figure out why the pool isn't
  creating more instances...
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.12  +32 -2     
xml-cocoon/src/org/apache/cocoon/util/Attic/ComponentPool.java
  
  Index: ComponentPool.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon/src/org/apache/cocoon/util/Attic/ComponentPool.java,v
  retrieving revision 1.1.2.11
  retrieving revision 1.1.2.12
  diff -u -r1.1.2.11 -r1.1.2.12
  --- ComponentPool.java        2001/03/01 19:29:05     1.1.2.11
  +++ ComponentPool.java        2001/03/01 20:12:23     1.1.2.12
  @@ -12,6 +12,7 @@
   import org.apache.avalon.util.pool.ThreadSafePool;
   import org.apache.avalon.util.pool.ObjectFactory;
   import org.apache.avalon.util.pool.PoolController;
  +import org.apache.avalon.util.pool.Resizable;
   import org.apache.cocoon.ComponentFactory;
   
   /**
  @@ -20,9 +21,9 @@
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Giacomo Pati</a>
    */
  -public class ComponentPool extends ThreadSafePool {
  +public class ComponentPool extends ThreadSafePool implements Resizable {
   
  -    public final static int DEFAULT_POOL_SIZE = 8;
  +    public final static int DEFAULT_POOL_SIZE = 16;
   
       public ComponentPool(final ObjectFactory factory) throws Exception {
           super(factory, DEFAULT_POOL_SIZE/2, DEFAULT_POOL_SIZE);
  @@ -37,5 +38,34 @@
                            final int initial,
                            final int maximum) throws Exception {
           super(factory, initial, maximum);
  +    }
  +
  +    public synchronized void grow(int amount) {
  +        if (m_currentCount >= m_max) {
  +            m_max += amount;
  +        } else {
  +            m_max = Math.max(m_currentCount + amount, m_max);
  +        }
  +
  +        while (m_currentCount < m_max) {
  +            try {
  +                 m_ready.add( m_factory.newInstance() );
  +                 m_currentCount++;
  +            } catch (Exception e) {
  +                getLogger().debug("Error growing the pool", e);
  +            }
  +        }
  +
  +        notify();
  +    }
  +
  +    public synchronized void shrink(int amount) {
  +        m_max -= amount;
  +
  +        while (m_currentCount > m_max) {
  +            m_ready.remove(0);
  +        }
  +
  +        notify();
       }
   }
  
  
  

Reply via email to