Home » commons-pool-1.5.4-src » org.apache.commons » pool » impl » [javadoc | source]
org.apache.commons.pool.impl
public class: GenericObjectPool [javadoc | source]
java.lang.Object
   org.apache.commons.pool.BaseObjectPool
      org.apache.commons.pool.impl.GenericObjectPool

All Implemented Interfaces:
    ObjectPool

A configurable ObjectPool implementation.

When coupled with the appropriate PoolableObjectFactory , GenericObjectPool provides robust pooling functionality for arbitrary objects.

A GenericObjectPool provides a number of configurable parameters:

Optionally, one may configure the pool to examine and possibly evict objects as they sit idle in the pool and to ensure that a minimum number of idle objects are available. This is performed by an "idle object eviction" thread, which runs asynchronously. Caution should be used when configuring this optional feature. Eviction runs require an exclusive synchronization lock on the pool, so if they run too frequently and / or incur excessive latency when creating, destroying or validating object instances, performance issues may result. The idle object eviction thread may be configured using the following attributes:

The pool can be configured to behave as a LIFO queue with respect to idle objects - always returning the most recently used object from the pool, or as a FIFO queue, where borrowObject always returns the oldest object in the idle object pool.

GenericObjectPool is not usable without a PoolableObjectFactory . A non-null factory must be provided either as a constructor argument or via a call to #setFactory before the pool is used.

Implementation note: To prevent possible deadlocks, care has been taken to ensure that no call to a factory method will occur within a synchronization block. See POOL-125 and DBCP-44 for more information.

Nested Class Summary:
public static class  GenericObjectPool.Config  A simple "struct" encapsulating the configuration information for a {@link GenericObjectPool}. 
Field Summary
public static final  byte WHEN_EXHAUSTED_FAIL    A "when exhausted action" type indicating that when the pool is exhausted (i.e., the maximum number of active objects has been reached), the #borrowObject method should fail, throwing a NoSuchElementException . 
public static final  byte WHEN_EXHAUSTED_BLOCK    A "when exhausted action" type indicating that when the pool is exhausted (i.e., the maximum number of active objects has been reached), the #borrowObject method should block until a new object is available, or the maximum wait time has been reached. 
public static final  byte WHEN_EXHAUSTED_GROW    A "when exhausted action" type indicating that when the pool is exhausted (i.e., the maximum number of active objects has been reached), the #borrowObject method should simply create a new object anyway. 
public static final  int DEFAULT_MAX_IDLE    The default cap on the number of "sleeping" instances in the pool. 
public static final  int DEFAULT_MIN_IDLE    The default minimum number of "sleeping" instances in the pool before before the evictor thread (if active) spawns new objects. 
public static final  int DEFAULT_MAX_ACTIVE    The default cap on the total number of active instances from the pool. 
public static final  byte DEFAULT_WHEN_EXHAUSTED_ACTION    The default "when exhausted action" for the pool. 
public static final  boolean DEFAULT_LIFO    The default LIFO status. True means that borrowObject returns the most recently used ("last in") idle object in the pool (if there are idle instances available). False means that the pool behaves as a FIFO queue - objects are taken from the idle object pool in the order that they are returned to the pool. 
public static final  long DEFAULT_MAX_WAIT    The default maximum amount of time (in milliseconds) the #borrowObject method should block before throwing an exception when the pool is exhausted and the "when exhausted" action is #WHEN_EXHAUSTED_BLOCK . 
public static final  boolean DEFAULT_TEST_ON_BORROW    The default "test on borrow" value. 
public static final  boolean DEFAULT_TEST_ON_RETURN    The default "test on return" value. 
public static final  boolean DEFAULT_TEST_WHILE_IDLE    The default "test while idle" value. 
public static final  long DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS    The default "time between eviction runs" value. 
public static final  int DEFAULT_NUM_TESTS_PER_EVICTION_RUN    The default number of objects to examine per run in the idle object evictor. 
public static final  long DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS    The default value for #getMinEvictableIdleTimeMillis . 
public static final  long DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS    The default value for #getSoftMinEvictableIdleTimeMillis . 
Constructor:
 public GenericObjectPool() 
 public GenericObjectPool(PoolableObjectFactory factory) 
    Create a new GenericObjectPool using the specified factory.
    Parameters:
    factory - the (possibly null)PoolableObjectFactory to use to create, validate and destroy objects
 public GenericObjectPool(PoolableObjectFactory factory,
    Config config) 
    Create a new GenericObjectPool using the specified values.
    Parameters:
    factory - the (possibly null)PoolableObjectFactory to use to create, validate and destroy objects
    config - a non-null GenericObjectPool.Config describing my configuration
 public GenericObjectPool(PoolableObjectFactory factory,
    int maxActive) 
    Create a new GenericObjectPool using the specified values.
    Parameters:
    factory - the (possibly null)PoolableObjectFactory to use to create, validate and destroy objects
    maxActive - the maximum number of objects that can be borrowed from me at one time (see #setMaxActive )
 public GenericObjectPool(PoolableObjectFactory factory,
    int maxActive,
    byte whenExhaustedAction,
    long maxWait) 
    Create a new GenericObjectPool using the specified values.
    Parameters:
    factory - the (possibly null)PoolableObjectFactory to use to create, validate and destroy objects
    maxActive - the maximum number of objects that can be borrowed from me at one time (see #setMaxActive )
    whenExhaustedAction - the action to take when the pool is exhausted (see #getWhenExhaustedAction )
    maxWait - the maximum amount of time to wait for an idle object when the pool is exhausted an and whenExhaustedAction is #WHEN_EXHAUSTED_BLOCK (otherwise ignored) (see #getMaxWait )
 public GenericObjectPool(PoolableObjectFactory factory,
    int maxActive,
    byte whenExhaustedAction,
    long maxWait,
    int maxIdle) 
    Create a new GenericObjectPool using the specified values.
    Parameters:
    factory - the (possibly null)PoolableObjectFactory to use to create, validate and destroy objects
    maxActive - the maximum number of objects that can be borrowed at one time (see #setMaxActive )
    whenExhaustedAction - the action to take when the pool is exhausted (see #getWhenExhaustedAction )
    maxWait - the maximum amount of time to wait for an idle object when the pool is exhausted and whenExhaustedAction is #WHEN_EXHAUSTED_BLOCK (otherwise ignored) (see #getMaxWait )
    maxIdle - the maximum number of idle objects in my pool (see #getMaxIdle )
 public GenericObjectPool(PoolableObjectFactory factory,
    int maxActive,
    byte whenExhaustedAction,
    long maxWait,
    boolean testOnBorrow,
    boolean testOnReturn) 
    Create a new GenericObjectPool using the specified values.
    Parameters:
    factory - the (possibly null)PoolableObjectFactory to use to create, validate and destroy objects
    maxActive - the maximum number of objects that can be borrowed at one time (see #setMaxActive )
    whenExhaustedAction - the action to take when the pool is exhausted (see #getWhenExhaustedAction )
    maxWait - the maximum amount of time to wait for an idle object when the pool is exhausted an and whenExhaustedAction is #WHEN_EXHAUSTED_BLOCK (otherwise ignored) (see #getMaxWait )
    testOnBorrow - whether or not to validate objects before they are returned by the #borrowObject method (see #getTestOnBorrow )
    testOnReturn - whether or not to validate objects after they are returned to the #returnObject method (see #getTestOnReturn )
 public GenericObjectPool(PoolableObjectFactory factory,
    int maxActive,
    byte whenExhaustedAction,
    long maxWait,
    int maxIdle,
    boolean testOnBorrow,
    boolean testOnReturn) 
    Create a new GenericObjectPool using the specified values.
    Parameters:
    factory - the (possibly null)PoolableObjectFactory to use to create, validate and destroy objects
    maxActive - the maximum number of objects that can be borrowed at one time (see #setMaxActive )
    whenExhaustedAction - the action to take when the pool is exhausted (see #getWhenExhaustedAction )
    maxWait - the maximum amount of time to wait for an idle object when the pool is exhausted and whenExhaustedAction is #WHEN_EXHAUSTED_BLOCK (otherwise ignored) (see #getMaxWait )
    maxIdle - the maximum number of idle objects in my pool (see #getMaxIdle )
    testOnBorrow - whether or not to validate objects before they are returned by the #borrowObject method (see #getTestOnBorrow )
    testOnReturn - whether or not to validate objects after they are returned to the #returnObject method (see #getTestOnReturn )
 public GenericObjectPool(PoolableObjectFactory factory,
    int maxActive,
    byte whenExhaustedAction,
    long maxWait,
    int maxIdle,
    boolean testOnBorrow,
    boolean testOnReturn,
    long timeBetweenEvictionRunsMillis,
    int numTestsPerEvictionRun,
    long minEvictableIdleTimeMillis,
    boolean testWhileIdle) 
    Create a new GenericObjectPool using the specified values.
    Parameters:
    factory - the (possibly null)PoolableObjectFactory to use to create, validate and destroy objects
    maxActive - the maximum number of objects that can be borrowed at one time (see #setMaxActive )
    whenExhaustedAction - the action to take when the pool is exhausted (see #setWhenExhaustedAction )
    maxWait - the maximum amount of time to wait for an idle object when the pool is exhausted and whenExhaustedAction is #WHEN_EXHAUSTED_BLOCK (otherwise ignored) (see #setMaxWait )
    maxIdle - the maximum number of idle objects in my pool (see #setMaxIdle )
    testOnBorrow - whether or not to validate objects before they are returned by the #borrowObject method (see #setTestOnBorrow )
    testOnReturn - whether or not to validate objects after they are returned to the #returnObject method (see #setTestOnReturn )
    timeBetweenEvictionRunsMillis - the amount of time (in milliseconds) to sleep between examining idle objects for eviction (see #setTimeBetweenEvictionRunsMillis )
    numTestsPerEvictionRun - the number of idle objects to examine per run within the idle object eviction thread (if any) (see #setNumTestsPerEvictionRun )
    minEvictableIdleTimeMillis - the minimum number of milliseconds an object can sit idle in the pool before it is eligible for eviction (see #setMinEvictableIdleTimeMillis )
    testWhileIdle - whether or not to validate objects in the idle object eviction thread, if any (see #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) 
    Create a new GenericObjectPool using the specified values.
    Parameters:
    factory - the (possibly null)PoolableObjectFactory to use to create, validate and destroy objects
    maxActive - the maximum number of objects that can be borrowed at one time (see #setMaxActive )
    whenExhaustedAction - the action to take when the pool is exhausted (see #setWhenExhaustedAction )
    maxWait - the maximum amount of time to wait for an idle object when the pool is exhausted and whenExhaustedAction is #WHEN_EXHAUSTED_BLOCK (otherwise ignored) (see #setMaxWait )
    maxIdle - the maximum number of idle objects in my pool (see #setMaxIdle )
    minIdle - the minimum number of idle objects in my pool (see #setMinIdle )
    testOnBorrow - whether or not to validate objects before they are returned by the #borrowObject method (see #setTestOnBorrow )
    testOnReturn - whether or not to validate objects after they are returned to the #returnObject method (see #setTestOnReturn )
    timeBetweenEvictionRunsMillis - the amount of time (in milliseconds) to sleep between examining idle objects for eviction (see #setTimeBetweenEvictionRunsMillis )
    numTestsPerEvictionRun - the number of idle objects to examine per run within the idle object eviction thread (if any) (see #setNumTestsPerEvictionRun )
    minEvictableIdleTimeMillis - the minimum number of milliseconds an object can sit idle in the pool before it is eligible for eviction (see #setMinEvictableIdleTimeMillis )
    testWhileIdle - whether or not to validate objects in the idle object eviction thread, if any (see #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,
    long softMinEvictableIdleTimeMillis) 
    Create a new GenericObjectPool using the specified values.
    Parameters:
    factory - the (possibly null)PoolableObjectFactory to use to create, validate and destroy objects
    maxActive - the maximum number of objects that can be borrowed at one time (see #setMaxActive )
    whenExhaustedAction - the action to take when the pool is exhausted (see #setWhenExhaustedAction )
    maxWait - the maximum amount of time to wait for an idle object when the pool is exhausted and whenExhaustedAction is #WHEN_EXHAUSTED_BLOCK (otherwise ignored) (see #setMaxWait )
    maxIdle - the maximum number of idle objects in my pool (see #setMaxIdle )
    minIdle - the minimum number of idle objects in my pool (see #setMinIdle )
    testOnBorrow - whether or not to validate objects before they are returned by the #borrowObject method (see #setTestOnBorrow )
    testOnReturn - whether or not to validate objects after they are returned to the #returnObject method (see #setTestOnReturn )
    timeBetweenEvictionRunsMillis - the amount of time (in milliseconds) to sleep between examining idle objects for eviction (see #setTimeBetweenEvictionRunsMillis )
    numTestsPerEvictionRun - the number of idle objects to examine per run within the idle object eviction thread (if any) (see #setNumTestsPerEvictionRun )
    minEvictableIdleTimeMillis - the minimum number of milliseconds an object can sit idle in the pool before it is eligible for eviction (see #setMinEvictableIdleTimeMillis )
    testWhileIdle - whether or not to validate objects in the idle object eviction thread, if any (see #setTestWhileIdle )
    softMinEvictableIdleTimeMillis - the minimum number of milliseconds an object can sit idle in the pool before it is eligible for eviction with the extra condition that at least "minIdle" amount of object remain in the pool. (see #setSoftMinEvictableIdleTimeMillis )
    since: Pool - 1.3
 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,
    long softMinEvictableIdleTimeMillis,
    boolean lifo) 
    Create a new GenericObjectPool using the specified values.
    Parameters:
    factory - the (possibly null)PoolableObjectFactory to use to create, validate and destroy objects
    maxActive - the maximum number of objects that can be borrowed at one time (see #setMaxActive )
    whenExhaustedAction - the action to take when the pool is exhausted (see #setWhenExhaustedAction )
    maxWait - the maximum amount of time to wait for an idle object when the pool is exhausted and whenExhaustedAction is #WHEN_EXHAUSTED_BLOCK (otherwise ignored) (see #setMaxWait )
    maxIdle - the maximum number of idle objects in my pool (see #setMaxIdle )
    minIdle - the minimum number of idle objects in my pool (see #setMinIdle )
    testOnBorrow - whether or not to validate objects before they are returned by the #borrowObject method (see #setTestOnBorrow )
    testOnReturn - whether or not to validate objects after they are returned to the #returnObject method (see #setTestOnReturn )
    timeBetweenEvictionRunsMillis - the amount of time (in milliseconds) to sleep between examining idle objects for eviction (see #setTimeBetweenEvictionRunsMillis )
    numTestsPerEvictionRun - the number of idle objects to examine per run within the idle object eviction thread (if any) (see #setNumTestsPerEvictionRun )
    minEvictableIdleTimeMillis - the minimum number of milliseconds an object can sit idle in the pool before it is eligible for eviction (see #setMinEvictableIdleTimeMillis )
    testWhileIdle - whether or not to validate objects in the idle object eviction thread, if any (see #setTestWhileIdle )
    softMinEvictableIdleTimeMillis - the minimum number of milliseconds an object can sit idle in the pool before it is eligible for eviction with the extra condition that at least "minIdle" amount of object remain in the pool. (see #setSoftMinEvictableIdleTimeMillis )
    lifo - whether or not objects are returned in last-in-first-out order from the idle object pool (see #setLifo )
    since: Pool - 1.4
Method from org.apache.commons.pool.impl.GenericObjectPool Summary:
addObject,   borrowObject,   clear,   close,   debugInfo,   evict,   getLifo,   getMaxActive,   getMaxIdle,   getMaxWait,   getMinEvictableIdleTimeMillis,   getMinIdle,   getNumActive,   getNumIdle,   getNumTestsPerEvictionRun,   getSoftMinEvictableIdleTimeMillis,   getTestOnBorrow,   getTestOnReturn,   getTestWhileIdle,   getTimeBetweenEvictionRunsMillis,   getWhenExhaustedAction,   invalidateObject,   returnObject,   setConfig,   setFactory,   setLifo,   setMaxActive,   setMaxIdle,   setMaxWait,   setMinEvictableIdleTimeMillis,   setMinIdle,   setNumTestsPerEvictionRun,   setSoftMinEvictableIdleTimeMillis,   setTestOnBorrow,   setTestOnReturn,   setTestWhileIdle,   setTimeBetweenEvictionRunsMillis,   setWhenExhaustedAction,   startEvictor
Methods from org.apache.commons.pool.BaseObjectPool:
addObject,   assertOpen,   borrowObject,   clear,   close,   getNumActive,   getNumIdle,   invalidateObject,   isClosed,   returnObject,   setFactory
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.apache.commons.pool.impl.GenericObjectPool Detail:
 public  void addObject() throws Exception 
    Create an object, and place it into the pool. addObject() is useful for "pre-loading" a pool with idle objects.
 public Object borrowObject() throws Exception 

    Borrows an object from the pool.

    If there is an idle instance available in the pool, then either the most-recently returned (if lifo == true) or "oldest" (lifo == false) instance sitting idle in the pool will be activated and returned. If activation fails, or testOnBorrow is set to true and validation fails, the instance is destroyed and the next available instance is examined. This continues until either a valid instance is returned or there are no more idle instances available.

    If there are no idle instances available in the pool, behavior depends on the maxActive and (if applicable) whenExhaustedAction and maxWait properties. If the number of instances checked out from the pool is less than maxActive, a new instance is created, activated and (if applicable) validated and returned to the caller.

    If the pool is exhausted (no available idle instances and no capacity to create new ones), this method will either block (#WHEN_EXHAUSTED_BLOCK ), throw a NoSuchElementException (#WHEN_EXHAUSTED_FAIL ), or grow (#WHEN_EXHAUSTED_GROW - ignoring maxActive). The length of time that this method will block when whenExhaustedAction == WHEN_EXHAUSTED_BLOCK is determined by the maxWait property.

    When the pool is exhausted, multiple calling threads may be simultaneously blocked waiting for instances to become available. As of pool 1.5, a "fairness" algorithm has been implemented to ensure that threads receive available instances in request arrival order.

 public  void clear() 
    Clears any objects sitting idle in the pool by removing them from the idle instance pool and then invoking the configured PoolableObjectFactory#destroyObject(Object) method on each idle instance.

    Implementation notes:

    • This method does not destroy or effect in any way instances that are checked out of the pool when it is invoked.
    • Invoking this method does not prevent objects being returned to the idle instance pool, even during its execution. It locks the pool only during instance removal. Additional instances may be returned while removed items are being destroyed.

 public  void close() throws Exception 
 synchronized String debugInfo() 
 public  void evict() throws Exception 

    Perform numTests idle object eviction tests, evicting examined objects that meet the criteria for eviction. If testWhileIdle is true, examined objects are validated when visited (and removed if invalid); otherwise only objects that have been idle for more than minEvicableIdletimeMillis are removed.

    Successive activations of this method examine objects in in sequence, cycling through objects in oldest-to-youngest order.

 public synchronized boolean getLifo() 
    Whether or not the idle object pool acts as a LIFO queue. True means that borrowObject returns the most recently used ("last in") idle object in the pool (if there are idle instances available). False means that the pool behaves as a FIFO queue - objects are taken from the idle object pool in the order that they are returned to the pool.
 public synchronized int getMaxActive() 
    Returns the maximum number of objects that can be allocated by the pool (checked out to clients, or idle awaiting checkout) at a given time. When non-positive, there is no limit to the number of objects that can be managed by the pool at one time.
 public synchronized int getMaxIdle() 
    Returns the cap on the number of "idle" instances in the pool.
 public synchronized long getMaxWait() 
 public synchronized long getMinEvictableIdleTimeMillis() 
    Returns the minimum amount of time an object may sit idle in the pool before it is eligible for eviction by the idle object evictor (if any).
 public synchronized int getMinIdle() 
    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)
 public synchronized int getNumActive() 
    Return the number of instances currently borrowed from this pool.
 public synchronized int getNumIdle() 
    Return the number of instances currently idle in this pool.
 public synchronized int getNumTestsPerEvictionRun() 
    Returns the max number of objects to examine during each run of the idle object evictor thread (if any).
 public synchronized long getSoftMinEvictableIdleTimeMillis() 
    Returns the minimum amount of time an object may sit idle in the pool before it is eligible for eviction by the idle object evictor (if any), with the extra condition that at least "minIdle" amount of object remain in the pool.
 public boolean getTestOnBorrow() 
    When true, objects will be validated before being returned by the #borrowObject method. If the object fails to validate, it will be dropped from the pool, and we will attempt to borrow another.
 public boolean getTestOnReturn() 
 public synchronized boolean getTestWhileIdle() 
    When true, objects will be validated by the idle object evictor (if any). If an object fails to validate, it will be dropped from the pool.
 public synchronized long getTimeBetweenEvictionRunsMillis() 
    Returns the number of milliseconds to sleep between runs of the idle object evictor thread. When non-positive, no idle object evictor thread will be run.
 public synchronized byte getWhenExhaustedAction() 
    Returns the action to take when the #borrowObject method is invoked when the pool is exhausted (the maximum number of "active" objects has been reached).
 public  void invalidateObject(Object obj) throws Exception 

    Invalidates the given object instance. Decrements the active count and destroys the instance.

 public  void returnObject(Object obj) throws Exception 

    Returns an object instance to the pool.

    If maxIdle is set to a positive value and the number of idle instances has reached this value, the returning instance is destroyed.

    If testOnReturn == true, the returning instance is validated before being returned to the idle instance pool. In this case, if validation fails, the instance is destroyed.

    Note: There is no guard to prevent an object being returned to the pool multiple times. Clients are expected to discard references to returned objects and ensure that an object is not returned to the pool multiple times in sequence (i.e., without being borrowed again between returns). Violating this contract will result in the same object appearing multiple times in the pool and pool counters (numActive, numIdle) returning incorrect values.

 public synchronized  void setConfig(Config conf) 
    Sets my configuration.
 public  void setFactory(PoolableObjectFactory factory) throws IllegalStateException 
    Sets the factory this pool uses to create new instances. Trying to change the factory while there are borrowed objects will throw an IllegalStateException .
 public synchronized  void setLifo(boolean lifo) 
    Sets the LIFO property of the pool. True means that borrowObject returns the most recently used ("last in") idle object in the pool (if there are idle instances available). False means that the pool behaves as a FIFO queue - objects are taken from the idle object pool in the order that they are returned to the pool.
 public synchronized  void setMaxActive(int maxActive) 
    Sets the cap on the number of objects that can be allocated by the pool (checked out to clients, or idle awaiting checkout) at a given time. Use a negative value for no limit.
 public synchronized  void setMaxIdle(int maxIdle) 
    Sets the cap on the number of "idle" instances in the pool. If maxIdle is set too low on heavily loaded systems it is possible you will see objects being destroyed and almost immediately new objects being created. This is a result of the active threads momentarily returning objects faster than they are requesting them them, causing the number of idle objects to rise above maxIdle. The best value for maxIdle for heavily loaded system will vary but the default is a good starting point.
 public synchronized  void setMaxWait(long maxWait) 
 public synchronized  void setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis) 
    Sets the minimum amount of time an object may sit idle in the pool before it is eligible for eviction by the idle object evictor (if any). When non-positive, no objects will be evicted from the pool due to idle time alone.
 public synchronized  void setMinIdle(int minIdle) 
    Sets the minimum number of objects allowed in the pool before the evictor thread (if active) spawns new objects. Note that no objects are created when numActive + numIdle >= maxActive. This setting has no effect if the idle object evictor is disabled (i.e. if timeBetweenEvictionRunsMillis <= 0).
 public synchronized  void setNumTestsPerEvictionRun(int numTestsPerEvictionRun) 
    Sets the max number of objects to examine during each run of the idle object evictor thread (if any).

    When a negative value is supplied, ceil(#getNumIdle )/abs(#getNumTestsPerEvictionRun ) tests will be run. That is, when the value is -n, roughly one nth of the idle objects will be tested per run. When the value is positive, the number of tests actually performed in each run will be the minimum of this value and the number of instances idle in the pool.

 public synchronized  void setSoftMinEvictableIdleTimeMillis(long softMinEvictableIdleTimeMillis) 
    Sets the minimum amount of time an object may sit idle in the pool before it is eligible for eviction by the idle object evictor (if any), with the extra condition that at least "minIdle" object instances remain in the pool. When non-positive, no objects will be evicted from the pool due to idle time alone.
 public  void setTestOnBorrow(boolean testOnBorrow) 
    When true, objects will be validated before being returned by the #borrowObject method. If the object fails to validate, it will be dropped from the pool, and we will attempt to borrow another.
 public  void setTestOnReturn(boolean testOnReturn) 
 public synchronized  void setTestWhileIdle(boolean testWhileIdle) 
    When true, objects will be validated by the idle object evictor (if any). If an object fails to validate, it will be dropped from the pool.
 public synchronized  void setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis) 
    Sets the number of milliseconds to sleep between runs of the idle object evictor thread. When non-positive, no idle object evictor thread will be run.
 public synchronized  void setWhenExhaustedAction(byte whenExhaustedAction) 
    Sets the action to take when the #borrowObject method is invoked when the pool is exhausted (the maximum number of "active" objects has been reached).
 protected synchronized  void startEvictor(long delay) 
    Start the eviction thread or service, or when delay is non-positive, stop it if it is already running.