commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From di...@apache.org
Subject cvs commit: jakarta-commons/pool/src/java/org/apache/commons/pool/impl GenericObjectPoolFactory.java GenericObjectPool.java
Date Thu, 21 Aug 2003 18:17:35 GMT
dirkv       2003/08/21 11:17:35

  Modified:    pool/src/java/org/apache/commons/pool/impl
                        GenericObjectPoolFactory.java
                        GenericObjectPool.java
  Log:
  Bugzilla Bug 22597:  minIdle Functionality
  
  - applied patch by Richard Wareing
  - compatibility
  - limit the number of objects created to maxActive
  
  Revision  Changes    Path
  1.3       +18 -12    jakarta-commons/pool/src/java/org/apache/commons/pool/impl/GenericObjectPoolFactory.java
  
  Index: GenericObjectPoolFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/pool/src/java/org/apache/commons/pool/impl/GenericObjectPoolFactory.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- GenericObjectPoolFactory.java	5 Mar 2003 19:17:08 -0000	1.2
  +++ GenericObjectPoolFactory.java	21 Aug 2003 18:17:35 -0000	1.3
  @@ -76,35 +76,40 @@
    */
   public class GenericObjectPoolFactory implements ObjectPoolFactory {
       public GenericObjectPoolFactory(PoolableObjectFactory factory) {
  -        this(factory,GenericObjectPool.DEFAULT_MAX_ACTIVE,GenericObjectPool.DEFAULT_WHEN_EXHAUSTED_ACTION,GenericObjectPool.DEFAULT_MAX_WAIT,GenericObjectPool.DEFAULT_MAX_IDLE,GenericObjectPool.DEFAULT_TEST_ON_BORROW,GenericObjectPool.DEFAULT_TEST_ON_RETURN,GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,GenericObjectPool.DEFAULT_TEST_WHILE_IDLE);
  +        this(factory,GenericObjectPool.DEFAULT_MAX_ACTIVE,GenericObjectPool.DEFAULT_WHEN_EXHAUSTED_ACTION,GenericObjectPool.DEFAULT_MAX_WAIT,GenericObjectPool.DEFAULT_MAX_IDLE,GenericObjectPool.DEFAULT_MIN_IDLE,GenericObjectPool.DEFAULT_TEST_ON_BORROW,GenericObjectPool.DEFAULT_TEST_ON_RETURN,GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,GenericObjectPool.DEFAULT_TEST_WHILE_IDLE);
       }
   
       public GenericObjectPoolFactory(PoolableObjectFactory factory, GenericObjectPool.Config
config) {
  -        this(factory,config.maxActive,config.whenExhaustedAction,config.maxWait,config.maxIdle,config.testOnBorrow,config.testOnReturn,config.timeBetweenEvictionRunsMillis,config.numTestsPerEvictionRun,config.minEvictableIdleTimeMillis,config.testWhileIdle);
  +        this(factory,config.maxActive,config.whenExhaustedAction,config.maxWait,config.maxIdle,config.minIdle,config.testOnBorrow,config.testOnReturn,config.timeBetweenEvictionRunsMillis,config.numTestsPerEvictionRun,config.minEvictableIdleTimeMillis,config.testWhileIdle);
       }
   
       public GenericObjectPoolFactory(PoolableObjectFactory factory, int maxActive) {
  -        this(factory,maxActive,GenericObjectPool.DEFAULT_WHEN_EXHAUSTED_ACTION,GenericObjectPool.DEFAULT_MAX_WAIT,GenericObjectPool.DEFAULT_MAX_IDLE,GenericObjectPool.DEFAULT_TEST_ON_BORROW,GenericObjectPool.DEFAULT_TEST_ON_RETURN,GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,GenericObjectPool.DEFAULT_TEST_WHILE_IDLE);
  +        this(factory,maxActive,GenericObjectPool.DEFAULT_WHEN_EXHAUSTED_ACTION,GenericObjectPool.DEFAULT_MAX_WAIT,GenericObjectPool.DEFAULT_MAX_IDLE,GenericObjectPool.DEFAULT_MIN_IDLE,GenericObjectPool.DEFAULT_TEST_ON_BORROW,GenericObjectPool.DEFAULT_TEST_ON_RETURN,GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,GenericObjectPool.DEFAULT_TEST_WHILE_IDLE);
       }
   
       public GenericObjectPoolFactory(PoolableObjectFactory factory, int maxActive, byte
whenExhaustedAction, long maxWait) {
  -        this(factory,maxActive,whenExhaustedAction,maxWait,GenericObjectPool.DEFAULT_MAX_IDLE,GenericObjectPool.DEFAULT_TEST_ON_BORROW,GenericObjectPool.DEFAULT_TEST_ON_RETURN,GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,GenericObjectPool.DEFAULT_TEST_WHILE_IDLE);
  +        this(factory,maxActive,whenExhaustedAction,maxWait,GenericObjectPool.DEFAULT_MAX_IDLE,GenericObjectPool.DEFAULT_MIN_IDLE,GenericObjectPool.DEFAULT_TEST_ON_BORROW,GenericObjectPool.DEFAULT_TEST_ON_RETURN,GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,GenericObjectPool.DEFAULT_TEST_WHILE_IDLE);
       }
   
       public GenericObjectPoolFactory(PoolableObjectFactory factory, int maxActive, byte
whenExhaustedAction, long maxWait, boolean testOnBorrow, boolean testOnReturn) {
  -        this(factory,maxActive,whenExhaustedAction,maxWait,GenericObjectPool.DEFAULT_MAX_IDLE,testOnBorrow,testOnReturn,GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,GenericObjectPool.DEFAULT_TEST_WHILE_IDLE);
  +        this(factory,maxActive,whenExhaustedAction,maxWait,GenericObjectPool.DEFAULT_MAX_IDLE,GenericObjectPool.DEFAULT_MIN_IDLE,testOnBorrow,testOnReturn,GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,GenericObjectPool.DEFAULT_TEST_WHILE_IDLE);
       }
   
       public GenericObjectPoolFactory(PoolableObjectFactory factory, int maxActive, byte
whenExhaustedAction, long maxWait, int maxIdle) {
  -        this(factory,maxActive,whenExhaustedAction,maxWait,maxIdle,GenericObjectPool.DEFAULT_TEST_ON_BORROW,GenericObjectPool.DEFAULT_TEST_ON_RETURN,GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,GenericObjectPool.DEFAULT_TEST_WHILE_IDLE);
  +        this(factory,maxActive,whenExhaustedAction,maxWait,maxIdle,GenericObjectPool.DEFAULT_MIN_IDLE,GenericObjectPool.DEFAULT_TEST_ON_BORROW,GenericObjectPool.DEFAULT_TEST_ON_RETURN,GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,GenericObjectPool.DEFAULT_TEST_WHILE_IDLE);
       }
   
       public GenericObjectPoolFactory(PoolableObjectFactory factory, int maxActive, byte
whenExhaustedAction, long maxWait, int maxIdle, boolean testOnBorrow, boolean testOnReturn)
{
  -        this(factory,maxActive,whenExhaustedAction,maxWait,maxIdle,testOnBorrow,testOnReturn,GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,GenericObjectPool.DEFAULT_TEST_WHILE_IDLE);
  +        this(factory,maxActive,whenExhaustedAction,maxWait,maxIdle,GenericObjectPool.DEFAULT_MIN_IDLE,testOnBorrow,testOnReturn,GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,GenericObjectPool.DEFAULT_TEST_WHILE_IDLE);
       }
   
       public GenericObjectPoolFactory(PoolableObjectFactory factory, int maxActive, byte
whenExhaustedAction, long maxWait, int maxIdle, boolean testOnBorrow, boolean testOnReturn,
long timeBetweenEvictionRunsMillis, int numTestsPerEvictionRun, long minEvictableIdleTimeMillis,
boolean testWhileIdle) {
  +        this(factory,maxActive,whenExhaustedAction,maxWait,maxIdle,GenericObjectPool.DEFAULT_MIN_IDLE,testOnBorrow,testOnReturn,GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,GenericObjectPool.DEFAULT_TEST_WHILE_IDLE);
  +    }
  +    
  +    public GenericObjectPoolFactory(PoolableObjectFactory factory, int maxActive, byte
whenExhaustedAction, long maxWait, int maxIdle, int minIdle, boolean testOnBorrow, boolean
testOnReturn, long timeBetweenEvictionRunsMillis, int numTestsPerEvictionRun, long minEvictableIdleTimeMillis,
boolean testWhileIdle) {
           _maxIdle = maxIdle;
  +        _minIdle = minIdle;
           _maxActive = maxActive;
           _maxWait = maxWait;
           _whenExhaustedAction = whenExhaustedAction;
  @@ -118,10 +123,11 @@
       }
   
       public ObjectPool createPool() {
  -        return new GenericObjectPool(_factory,_maxActive,_whenExhaustedAction,_maxWait,_maxIdle,_testOnBorrow,_testOnReturn,_timeBetweenEvictionRunsMillis,_numTestsPerEvictionRun,_minEvictableIdleTimeMillis,_testWhileIdle);
  +        return new GenericObjectPool(_factory,_maxActive,_whenExhaustedAction,_maxWait,_maxIdle,_minIdle,_testOnBorrow,_testOnReturn,_timeBetweenEvictionRunsMillis,_numTestsPerEvictionRun,_minEvictableIdleTimeMillis,_testWhileIdle);
       }
   
       protected int _maxIdle = GenericObjectPool.DEFAULT_MAX_IDLE;
  +    protected int _minIdle = GenericObjectPool.DEFAULT_MIN_IDLE;
       protected int _maxActive = GenericObjectPool.DEFAULT_MAX_ACTIVE;
       protected long _maxWait = GenericObjectPool.DEFAULT_MAX_WAIT;
       protected byte _whenExhaustedAction = GenericObjectPool.DEFAULT_WHEN_EXHAUSTED_ACTION;
  
  
  
  1.25      +87 -12    jakarta-commons/pool/src/java/org/apache/commons/pool/impl/GenericObjectPool.java
  
  Index: GenericObjectPool.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/pool/src/java/org/apache/commons/pool/impl/GenericObjectPool.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- GenericObjectPool.java	15 Aug 2003 13:34:05 -0000	1.24
  +++ GenericObjectPool.java	21 Aug 2003 18:17:35 -0000	1.25
  @@ -214,6 +214,14 @@
       public static final int DEFAULT_MAX_IDLE  = 8;
   
       /**
  +     * The default minimum number of "sleeping" instances in the pool
  +     * before before the evictor thread (if active) spawns new objects.
  +     * @see #getMinIdle
  +     * @see #setMinIdle
  +     */
  +    public static final int DEFAULT_MIN_IDLE = 0;
  +
  +    /**
        * The default cap on the total number of active instances from the pool.
        * @see #getMaxActive
        */
  @@ -292,7 +300,7 @@
        * Create a new <tt>GenericObjectPool</tt>.
        */
       public GenericObjectPool() {
  -        this(null,DEFAULT_MAX_ACTIVE,DEFAULT_WHEN_EXHAUSTED_ACTION,DEFAULT_MAX_WAIT,DEFAULT_MAX_IDLE,DEFAULT_TEST_ON_BORROW,DEFAULT_TEST_ON_RETURN,DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,DEFAULT_NUM_TESTS_PER_EVICTION_RUN,DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,DEFAULT_TEST_WHILE_IDLE);
  +        this(null,DEFAULT_MAX_ACTIVE,DEFAULT_WHEN_EXHAUSTED_ACTION,DEFAULT_MAX_WAIT,DEFAULT_MAX_IDLE,DEFAULT_MIN_IDLE,DEFAULT_TEST_ON_BORROW,DEFAULT_TEST_ON_RETURN,DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,DEFAULT_NUM_TESTS_PER_EVICTION_RUN,DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,DEFAULT_TEST_WHILE_IDLE);
       }
   
       /**
  @@ -300,7 +308,7 @@
        * @param factory the (possibly <tt>null</tt>)PoolableObjectFactory to
use to create, validate and destroy objects
        */
       public GenericObjectPool(PoolableObjectFactory factory) {
  -        this(factory,DEFAULT_MAX_ACTIVE,DEFAULT_WHEN_EXHAUSTED_ACTION,DEFAULT_MAX_WAIT,DEFAULT_MAX_IDLE,DEFAULT_TEST_ON_BORROW,DEFAULT_TEST_ON_RETURN,DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,DEFAULT_NUM_TESTS_PER_EVICTION_RUN,DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,DEFAULT_TEST_WHILE_IDLE);
  +        this(factory,DEFAULT_MAX_ACTIVE,DEFAULT_WHEN_EXHAUSTED_ACTION,DEFAULT_MAX_WAIT,DEFAULT_MAX_IDLE,DEFAULT_MIN_IDLE,DEFAULT_TEST_ON_BORROW,DEFAULT_TEST_ON_RETURN,DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,DEFAULT_NUM_TESTS_PER_EVICTION_RUN,DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,DEFAULT_TEST_WHILE_IDLE);
       }
   
       /**
  @@ -309,7 +317,7 @@
        * @param config a non-<tt>null</tt> {@link GenericObjectPool.Config} describing
my configuration
        */
       public GenericObjectPool(PoolableObjectFactory factory, GenericObjectPool.Config config)
{
  -        this(factory,config.maxActive,config.whenExhaustedAction,config.maxWait,config.maxIdle,config.testOnBorrow,config.testOnReturn,config.timeBetweenEvictionRunsMillis,config.numTestsPerEvictionRun,config.minEvictableIdleTimeMillis,config.testWhileIdle);
  +        this(factory,config.maxActive,config.whenExhaustedAction,config.maxWait,config.maxIdle,config.minIdle,config.testOnBorrow,config.testOnReturn,config.timeBetweenEvictionRunsMillis,config.numTestsPerEvictionRun,config.minEvictableIdleTimeMillis,config.testWhileIdle);
       }
   
       /**
  @@ -318,7 +326,7 @@
        * @param maxActive the maximum number of objects that can be borrowed from me at one
time (see {@link #setMaxActive})
        */
       public GenericObjectPool(PoolableObjectFactory factory, int maxActive) {
  -        this(factory,maxActive,DEFAULT_WHEN_EXHAUSTED_ACTION,DEFAULT_MAX_WAIT,DEFAULT_MAX_IDLE,DEFAULT_TEST_ON_BORROW,DEFAULT_TEST_ON_RETURN,DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,DEFAULT_NUM_TESTS_PER_EVICTION_RUN,DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,DEFAULT_TEST_WHILE_IDLE);
  +        this(factory,maxActive,DEFAULT_WHEN_EXHAUSTED_ACTION,DEFAULT_MAX_WAIT,DEFAULT_MAX_IDLE,DEFAULT_MIN_IDLE,DEFAULT_TEST_ON_BORROW,DEFAULT_TEST_ON_RETURN,DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,DEFAULT_NUM_TESTS_PER_EVICTION_RUN,DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,DEFAULT_TEST_WHILE_IDLE);
       }
   
       /**
  @@ -329,7 +337,7 @@
        * @param maxWait the maximum amount of time to wait for an idle object when the pool
is exhausted an and <i>whenExhaustedAction</i> is {@link #WHEN_EXHAUSTED_BLOCK}
(otherwise ignored) (see {@link #getMaxWait})
        */
       public GenericObjectPool(PoolableObjectFactory factory, int maxActive, byte whenExhaustedAction,
long maxWait) {
  -        this(factory,maxActive,whenExhaustedAction,maxWait,DEFAULT_MAX_IDLE,DEFAULT_TEST_ON_BORROW,DEFAULT_TEST_ON_RETURN,DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,DEFAULT_NUM_TESTS_PER_EVICTION_RUN,DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,DEFAULT_TEST_WHILE_IDLE);
  +        this(factory,maxActive,whenExhaustedAction,maxWait,DEFAULT_MAX_IDLE,DEFAULT_MIN_IDLE,DEFAULT_TEST_ON_BORROW,DEFAULT_TEST_ON_RETURN,DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,DEFAULT_NUM_TESTS_PER_EVICTION_RUN,DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,DEFAULT_TEST_WHILE_IDLE);
       }
   
       /**
  @@ -342,7 +350,7 @@
        * @param testOnReturn whether or not to validate objects after they are returned to
the {@link #returnObject} method (see {@link #getTestOnReturn})
        */
       public GenericObjectPool(PoolableObjectFactory factory, int maxActive, byte whenExhaustedAction,
long maxWait, boolean testOnBorrow, boolean testOnReturn) {
  -        this(factory,maxActive,whenExhaustedAction,maxWait,DEFAULT_MAX_IDLE,testOnBorrow,testOnReturn,DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,DEFAULT_NUM_TESTS_PER_EVICTION_RUN,DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,DEFAULT_TEST_WHILE_IDLE);
  +        this(factory,maxActive,whenExhaustedAction,maxWait,DEFAULT_MAX_IDLE,DEFAULT_MIN_IDLE,testOnBorrow,testOnReturn,DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,DEFAULT_NUM_TESTS_PER_EVICTION_RUN,DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,DEFAULT_TEST_WHILE_IDLE);
       }
   
       /**
  @@ -354,7 +362,7 @@
        * @param maxIdle the maximum number of idle objects in my pool (see {@link #getMaxIdle})
        */
       public GenericObjectPool(PoolableObjectFactory factory, int maxActive, byte whenExhaustedAction,
long maxWait, int maxIdle) {
  -        this(factory,maxActive,whenExhaustedAction,maxWait,maxIdle,DEFAULT_TEST_ON_BORROW,DEFAULT_TEST_ON_RETURN,DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,DEFAULT_NUM_TESTS_PER_EVICTION_RUN,DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,DEFAULT_TEST_WHILE_IDLE);
  +        this(factory,maxActive,whenExhaustedAction,maxWait,maxIdle,DEFAULT_MIN_IDLE,DEFAULT_TEST_ON_BORROW,DEFAULT_TEST_ON_RETURN,DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,DEFAULT_NUM_TESTS_PER_EVICTION_RUN,DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,DEFAULT_TEST_WHILE_IDLE);
       }
   
       /**
  @@ -368,7 +376,7 @@
        * @param testOnReturn whether or not to validate objects after they are returned to
the {@link #returnObject} method (see {@link #getTestOnReturn})
        */
       public GenericObjectPool(PoolableObjectFactory factory, int maxActive, byte whenExhaustedAction,
long maxWait, int maxIdle, boolean testOnBorrow, boolean testOnReturn) {
  -        this(factory,maxActive,whenExhaustedAction,maxWait,maxIdle,testOnBorrow,testOnReturn,DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,DEFAULT_NUM_TESTS_PER_EVICTION_RUN,DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,DEFAULT_TEST_WHILE_IDLE);
  +        this(factory,maxActive,whenExhaustedAction,maxWait,maxIdle,DEFAULT_MIN_IDLE,testOnBorrow,testOnReturn,DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,DEFAULT_NUM_TESTS_PER_EVICTION_RUN,DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,DEFAULT_TEST_WHILE_IDLE);
       }
   
       /**
  @@ -386,6 +394,25 @@
        * @param testWhileIdle whether or not to validate objects in the idle object eviction
thread, if any (see {@link #setTestWhileIdle})
        */
       public GenericObjectPool(PoolableObjectFactory factory, int maxActive, byte whenExhaustedAction,
long maxWait, int maxIdle, boolean testOnBorrow, boolean testOnReturn, long timeBetweenEvictionRunsMillis,
int numTestsPerEvictionRun, long minEvictableIdleTimeMillis, boolean testWhileIdle) {
  +        this(factory, maxActive, whenExhaustedAction, maxWait, maxIdle, DEFAULT_MIN_IDLE,
testOnBorrow, testOnReturn, timeBetweenEvictionRunsMillis, numTestsPerEvictionRun, minEvictableIdleTimeMillis,
testWhileIdle);
  +    }
  +
  +    /**
  +     * Create a new <tt>GenericObjectPool</tt> using the specified values.
  +     * @param factory the (possibly <tt>null</tt>)PoolableObjectFactory to
use to create, validate and destroy objects
  +     * @param maxActive the maximum number of objects that can be borrowed from me at one
time (see {@link #setMaxActive})
  +     * @param whenExhaustedAction the action to take when the pool is exhausted (see {@link
#setWhenExhaustedAction})
  +     * @param maxWait the maximum amount of time to wait for an idle object when the pool
is exhausted an and <i>whenExhaustedAction</i> is {@link #WHEN_EXHAUSTED_BLOCK}
(otherwise ignored) (see {@link #setMaxWait})
  +     * @param maxIdle the maximum number of idle objects in my pool (see {@link #setMaxIdle})
  +     * @param minIdle the minimum number of idle objects in my pool (see {@link #setMinIdle})
  +     * @param testOnBorrow whether or not to validate objects before they are returned
by the {@link #borrowObject} method (see {@link #setTestOnBorrow})
  +     * @param testOnReturn whether or not to validate objects after they are returned to
the {@link #returnObject} method (see {@link #setTestOnReturn})
  +     * @param timeBetweenEvictionRunsMillis the amount of time (in milliseconds) to sleep
between examining idle objects for eviction (see {@link #setTimeBetweenEvictionRunsMillis})
  +     * @param numTestsPerEvictionRun the number of idle objects to examine per run within
the idle object eviction thread (if any) (see {@link #setNumTestsPerEvictionRun})
  +     * @param minEvictableIdleTimeMillis the minimum number of milliseconds an object can
sit idle in the pool before it is eligable for evcition (see {@link #setMinEvictableIdleTimeMillis})
  +     * @param testWhileIdle whether or not to validate objects in the idle object eviction
thread, if any (see {@link #setTestWhileIdle})
  +     */
  +    public GenericObjectPool(PoolableObjectFactory factory, int maxActive, byte whenExhaustedAction,
long maxWait, int maxIdle, int minIdle, boolean testOnBorrow, boolean testOnReturn, long timeBetweenEvictionRunsMillis,
int numTestsPerEvictionRun, long minEvictableIdleTimeMillis, boolean testWhileIdle) {
           _factory = factory;
           _maxActive = maxActive;
           switch(whenExhaustedAction) {
  @@ -399,6 +426,7 @@
           }
           _maxWait = maxWait;
           _maxIdle = maxIdle;
  +        _minIdle = minIdle;
           _testOnBorrow = testOnBorrow;
           _testOnReturn = testOnReturn;
           _timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
  @@ -532,6 +560,33 @@
       }
   
       /**
  +     * Sets the minimum number of objects allowed in the pool
  +     * before the evictor thread (if active) spawns new objects.
  +     * (Note no objects are created when: numActive + numIdle >= maxActive)
  +     * 
  +     * @param minIdle The minimum number of objects. 
  +     * @see #getMinIdle
  +     */
  +    public void setMinIdle(int minIdle) {
  +        _minIdle = minIdle;
  +        synchronized(this) {
  +            notifyAll();
  +        }
  +    }
  +
  +    /**
  +     * Returns the minimum number of objects allowed in the pool
  +     * before the evictor thread (if active) spawns new objects.
  +     * (Note no objects are created when: numActive + numIdle >= maxActive)
  +     *
  +     * @return The minimum number of objects.
  +     * @see #setMinIdle
  +     */
  +    public synchronized int getMinIdle() {
  +        return _minIdle;
  +    }
  +
  +    /**
        * When <tt>true</tt>, objects will be
        * {@link PoolableObjectFactory#validateObject validated}
        * before being returned by the {@link #borrowObject}
  @@ -692,6 +747,7 @@
        */
       public synchronized void setConfig(GenericObjectPool.Config conf) {
           setMaxIdle(conf.maxIdle);
  +        setMinIdle(conf.minIdle);
           setMaxActive(conf.maxActive);
           setMaxWait(conf.maxWait);
           setWhenExhaustedAction(conf.whenExhaustedAction);
  @@ -942,6 +998,17 @@
                       }
                   }
               }
  +        } // if !empty
  +        
  +        // Check to see if we are below our minimum number of objects
  +        // if so enough to bring us back to our minimum.
  +        int objectDeficit = getMinIdle() - getNumIdle();
  +        if (_maxActive > 0) {
  +            int growLimit = Math.max(0, getMaxActive() - getNumActive() - getNumIdle());
  +            objectDeficit = Math.min(objectDeficit, growLimit);
  +        }
  +        for ( int j = 0; j < objectDeficit; j++ ) {
  +            addObject();
           }
       }
   
  @@ -1065,6 +1132,7 @@
        */
       public static class Config {
           public int maxIdle = GenericObjectPool.DEFAULT_MAX_IDLE;
  +        public int minIdle = GenericObjectPool.DEFAULT_MIN_IDLE;
           public int maxActive = GenericObjectPool.DEFAULT_MAX_ACTIVE;
           public long maxWait = GenericObjectPool.DEFAULT_MAX_WAIT;
           public byte whenExhaustedAction = GenericObjectPool.DEFAULT_WHEN_EXHAUSTED_ACTION;
  @@ -1084,6 +1152,13 @@
        * @see #getMaxIdle
        */
       private int _maxIdle = DEFAULT_MAX_IDLE;
  +
  +    /**
  +    * The cap on the minimum number of idle instances in the pool.
  +    * @see #setMinIdle
  +    * @see #getMinIdle
  +    */
  +   private int _minIdle = DEFAULT_MIN_IDLE;
   
       /**
        * The cap on the total number of active instances from the pool.
  
  
  

Mime
View raw message