| java.lang.Object org.apache.commons.pool.BaseKeyedObjectPool org.apache.commons.pool.impl.GenericKeyedObjectPool
GenericKeyedObjectPool | public class GenericKeyedObjectPool extends BaseKeyedObjectPool implements KeyedObjectPool(Code) | | A configurable
KeyedObjectPool implementation.
When coupled with the appropriate
KeyedPoolableObjectFactory ,
GenericKeyedObjectPool provides robust pooling functionality for
arbitrary objects.
A GenericKeyedObjectPool 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. This is performed by an "idle object eviction" thread, which
runs asychronously. The idle object eviction thread may be configured using the
following attributes:
GenericKeyedObjectPool is not usable without a
KeyedPoolableObjectFactory . A
non-null factory must be provided either as a constructor argument
or via a call to
GenericKeyedObjectPool.setFactory before the pool is used.
See Also: GenericObjectPool author: Rodney Waldhoff author: Dirk Verbeeck version: $Revision: 386116 $ $Date: 2006-03-15 12:15:58 -0500 (Wed, 15 Mar 2006) $ |
Inner Class :static class ObjectTimestampPair implements Comparable | |
Inner Class :public static class Config | |
Constructor Summary | |
public | GenericKeyedObjectPool() Create a new GenericKeyedObjectPool.. | public | GenericKeyedObjectPool(KeyedPoolableObjectFactory factory) Create a new GenericKeyedObjectPool using the specified values. | public | GenericKeyedObjectPool(KeyedPoolableObjectFactory factory, GenericKeyedObjectPool.Config config) Create a new GenericKeyedObjectPool using the specified values. | public | GenericKeyedObjectPool(KeyedPoolableObjectFactory factory, int maxActive) Create a new GenericKeyedObjectPool using the specified values. | public | GenericKeyedObjectPool(KeyedPoolableObjectFactory factory, int maxActive, byte whenExhaustedAction, long maxWait) Create a new GenericKeyedObjectPool using the specified values. | public | GenericKeyedObjectPool(KeyedPoolableObjectFactory factory, int maxActive, byte whenExhaustedAction, long maxWait, boolean testOnBorrow, boolean testOnReturn) Create a new GenericKeyedObjectPool using the specified values. | public | GenericKeyedObjectPool(KeyedPoolableObjectFactory factory, int maxActive, byte whenExhaustedAction, long maxWait, int maxIdle) Create a new GenericKeyedObjectPool using the specified values. | public | GenericKeyedObjectPool(KeyedPoolableObjectFactory factory, int maxActive, byte whenExhaustedAction, long maxWait, int maxIdle, boolean testOnBorrow, boolean testOnReturn) Create a new GenericKeyedObjectPool using the specified values. | public | GenericKeyedObjectPool(KeyedPoolableObjectFactory factory, int maxActive, byte whenExhaustedAction, long maxWait, int maxIdle, boolean testOnBorrow, boolean testOnReturn, long timeBetweenEvictionRunsMillis, int numTestsPerEvictionRun, long minEvictableIdleTimeMillis, boolean testWhileIdle) Create a new GenericKeyedObjectPool using the specified values. | public | GenericKeyedObjectPool(KeyedPoolableObjectFactory factory, int maxActive, byte whenExhaustedAction, long maxWait, int maxIdle, int maxTotal, boolean testOnBorrow, boolean testOnReturn, long timeBetweenEvictionRunsMillis, int numTestsPerEvictionRun, long minEvictableIdleTimeMillis, boolean testWhileIdle) Create a new GenericKeyedObjectPool using the specified values. | public | GenericKeyedObjectPool(KeyedPoolableObjectFactory factory, int maxActive, byte whenExhaustedAction, long maxWait, int maxIdle, int maxTotal, int minIdle, boolean testOnBorrow, boolean testOnReturn, long timeBetweenEvictionRunsMillis, int numTestsPerEvictionRun, long minEvictableIdleTimeMillis, boolean testWhileIdle) Create a new GenericKeyedObjectPool using the specified values. |
Method Summary | |
public synchronized void | addObject(Object key) | public synchronized Object | borrowObject(Object key) | public synchronized void | clear() | public synchronized void | clear(Object key) | public synchronized void | clearOldest() Method clears oldest 15% of objects in pool. | public synchronized void | close() | synchronized String | debugInfo() | public synchronized void | evict() | public synchronized int | getMaxActive() Returns the cap on the number of active instances from my pool (per key). | public synchronized int | getMaxIdle() Returns the cap on the number of "idle" instances in the pool. | public synchronized int | getMaxTotal() Returns the cap on the total number of instances from my pool if non-positive. | public synchronized long | getMaxWait() Returns the maximum amount of time (in milliseconds) the
GenericKeyedObjectPool.borrowObject method should block before throwing
an exception when the pool is exhausted and the
GenericKeyedObjectPool.setWhenExhaustedAction "when exhausted" action is
GenericKeyedObjectPool.WHEN_EXHAUSTED_BLOCK . | public synchronized long | getMinEvictableIdleTimeMillis() Returns the minimum amount of time an object may sit idle in the pool
before it is eligable for eviction by the idle object evictor
(if any). | public synchronized int | getMinIdle() | public synchronized int | getNumActive() | public synchronized int | getNumActive(Object key) | public synchronized int | getNumIdle() | public synchronized int | getNumIdle(Object key) | public synchronized int | getNumTestsPerEvictionRun() Returns the number of objects to examine during each run of the
idle object evictor thread (if any). | public synchronized boolean | getTestOnBorrow() When true, objects will be
org.apache.commons.pool.PoolableObjectFactory.validateObject validated before being returned by the
GenericKeyedObjectPool.borrowObject method. | public synchronized boolean | getTestOnReturn() When true, objects will be
org.apache.commons.pool.PoolableObjectFactory.validateObject validated before being returned to the pool within the
GenericKeyedObjectPool.returnObject . | public synchronized boolean | getTestWhileIdle() When true, objects will be
org.apache.commons.pool.PoolableObjectFactory.validateObject validated by the idle object evictor (if any). | public synchronized long | getTimeBetweenEvictionRunsMillis() Returns the number of milliseconds to sleep between runs of the
idle object evictor thread. | public synchronized byte | getWhenExhaustedAction() Returns the action to take when the
GenericKeyedObjectPool.borrowObject method
is invoked when the pool is exhausted (the maximum number
of "active" objects has been reached). | public synchronized void | invalidateObject(Object key, Object obj) | public synchronized void | preparePool(Object key, boolean populateImmediately) Registers a key for pool control.
If populateImmediately is true , the pool will immediately commence
a sustain cycle. | public synchronized void | returnObject(Object key, Object obj) | public synchronized void | setConfig(GenericKeyedObjectPool.Config conf) Sets my configuration. | public synchronized void | setFactory(KeyedPoolableObjectFactory factory) | public synchronized void | setMaxActive(int maxActive) Sets the cap on the number of active instances from my pool (per key). | public synchronized void | setMaxIdle(int maxIdle) Sets the cap on the number of "idle" instances in the pool. | public synchronized void | setMaxTotal(int maxTotal) Sets the cap on the total number of instances from my pool if non-positive. | public synchronized void | setMaxWait(long maxWait) Sets the maximum amount of time (in milliseconds) the
GenericKeyedObjectPool.borrowObject method should block before throwing
an exception when the pool is exhausted and the
GenericKeyedObjectPool.setWhenExhaustedAction "when exhausted" action is
GenericKeyedObjectPool.WHEN_EXHAUSTED_BLOCK . | public synchronized void | setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis) Sets the minimum amount of time an object may sit idle in the pool
before it is eligable for eviction by the idle object evictor
(if any). | public synchronized void | setMinIdle(int poolSize) | public synchronized void | setNumTestsPerEvictionRun(int numTestsPerEvictionRun) Sets the number of objects to examine during each run of the
idle object evictor thread (if any).
When a negative value is supplied, ceil(
GenericKeyedObjectPool.getNumIdle )/abs(
GenericKeyedObjectPool.getNumTestsPerEvictionRun )
tests will be run. | public synchronized void | setTestOnBorrow(boolean testOnBorrow) When true, objects will be
org.apache.commons.pool.PoolableObjectFactory.validateObject validated before being returned by the
GenericKeyedObjectPool.borrowObject method. | public synchronized void | setTestOnReturn(boolean testOnReturn) When true, objects will be
org.apache.commons.pool.PoolableObjectFactory.validateObject validated before being returned to the pool within the
GenericKeyedObjectPool.returnObject . | public synchronized void | setTestWhileIdle(boolean testWhileIdle) When true, objects will be
org.apache.commons.pool.PoolableObjectFactory.validateObject validated by the idle object evictor (if any). | public synchronized void | setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis) Sets the number of milliseconds to sleep between runs of the
idle object evictor thread. | public synchronized void | setWhenExhaustedAction(byte whenExhaustedAction) Sets the action to take when the
GenericKeyedObjectPool.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. |
GenericKeyedObjectPool | public GenericKeyedObjectPool()(Code) | | Create a new GenericKeyedObjectPool..
|
GenericKeyedObjectPool | public GenericKeyedObjectPool(KeyedPoolableObjectFactory factory)(Code) | | Create a new GenericKeyedObjectPool using the specified values.
Parameters: factory - the (possibly null)KeyedPoolableObjectFactory to use to create, validate and destroy objects |
GenericKeyedObjectPool | public GenericKeyedObjectPool(KeyedPoolableObjectFactory factory, int maxActive)(Code) | | Create a new GenericKeyedObjectPool using the specified values.
Parameters: factory - the (possibly null)KeyedPoolableObjectFactory to use to create, validate and destroy objects Parameters: maxActive - the maximum number of objects that can be borrowed from me at one time (per key) (see GenericKeyedObjectPool.setMaxActive) |
GenericKeyedObjectPool | public GenericKeyedObjectPool(KeyedPoolableObjectFactory factory, int maxActive, byte whenExhaustedAction, long maxWait, int maxIdle, boolean testOnBorrow, boolean testOnReturn, long timeBetweenEvictionRunsMillis, int numTestsPerEvictionRun, long minEvictableIdleTimeMillis, boolean testWhileIdle)(Code) | | Create a new GenericKeyedObjectPool using the specified values.
Parameters: factory - the (possibly null)PoolableObjectFactory to use to create, validate and destroy objects Parameters: maxActive - the maximum number of objects that can be borrowed from me at one time (per key) (see GenericKeyedObjectPool.setMaxActive) Parameters: whenExhaustedAction - the action to take when the pool is exhausted (see GenericKeyedObjectPool.setWhenExhaustedAction) Parameters: maxWait - the maximum amount of time to wait for an idle object when the pool is exhausted an and whenExhaustedAction is GenericKeyedObjectPool.WHEN_EXHAUSTED_BLOCK (otherwise ignored) (see GenericKeyedObjectPool.setMaxWait) Parameters: maxIdle - the maximum number of idle objects in my pool (see GenericKeyedObjectPool.setMaxIdle) Parameters: testOnBorrow - whether or not to validate objects before they are returned by the GenericKeyedObjectPool.borrowObject method (see GenericKeyedObjectPool.setTestOnBorrow) Parameters: testOnReturn - whether or not to validate objects after they are returned to the GenericKeyedObjectPool.returnObject method (see GenericKeyedObjectPool.setTestOnReturn) Parameters: timeBetweenEvictionRunsMillis - the amount of time (in milliseconds) to sleep between examining idle objects for eviction (see GenericKeyedObjectPool.setTimeBetweenEvictionRunsMillis) Parameters: numTestsPerEvictionRun - the number of idle objects to examine per run within the idle object eviction thread (if any) (see GenericKeyedObjectPool.setNumTestsPerEvictionRun) Parameters: minEvictableIdleTimeMillis - the minimum number of milliseconds an object can sit idle in the pool before it is eligable for evcition (see GenericKeyedObjectPool.setMinEvictableIdleTimeMillis) Parameters: testWhileIdle - whether or not to validate objects in the idle object eviction thread, if any (see GenericKeyedObjectPool.setTestWhileIdle) |
GenericKeyedObjectPool | public GenericKeyedObjectPool(KeyedPoolableObjectFactory factory, int maxActive, byte whenExhaustedAction, long maxWait, int maxIdle, int maxTotal, boolean testOnBorrow, boolean testOnReturn, long timeBetweenEvictionRunsMillis, int numTestsPerEvictionRun, long minEvictableIdleTimeMillis, boolean testWhileIdle)(Code) | | Create a new GenericKeyedObjectPool using the specified values.
Parameters: factory - the (possibly null)PoolableObjectFactory to use to create, validate and destroy objects Parameters: maxActive - the maximum number of objects that can be borrowed from me at one time (per key) (see GenericKeyedObjectPool.setMaxActive) Parameters: whenExhaustedAction - the action to take when the pool is exhausted (see GenericKeyedObjectPool.setWhenExhaustedAction) Parameters: maxWait - the maximum amount of time to wait for an idle object when the pool is exhausted an and whenExhaustedAction is GenericKeyedObjectPool.WHEN_EXHAUSTED_BLOCK (otherwise ignored) (see GenericKeyedObjectPool.setMaxWait) Parameters: maxIdle - the maximum number of idle objects in my pool (see GenericKeyedObjectPool.setMaxIdle) Parameters: maxTotal - the maximum number of objects that can exists at one time (see GenericKeyedObjectPool.setMaxTotal) Parameters: testOnBorrow - whether or not to validate objects before they are returned by the GenericKeyedObjectPool.borrowObject method (see GenericKeyedObjectPool.setTestOnBorrow) Parameters: testOnReturn - whether or not to validate objects after they are returned to the GenericKeyedObjectPool.returnObject method (see GenericKeyedObjectPool.setTestOnReturn) Parameters: timeBetweenEvictionRunsMillis - the amount of time (in milliseconds) to sleep between examining idle objects for eviction (see GenericKeyedObjectPool.setTimeBetweenEvictionRunsMillis) Parameters: numTestsPerEvictionRun - the number of idle objects to examine per run within the idle object eviction thread (if any) (see GenericKeyedObjectPool.setNumTestsPerEvictionRun) Parameters: minEvictableIdleTimeMillis - the minimum number of milliseconds an object can sit idle in the pool before it is eligable for evcition (see GenericKeyedObjectPool.setMinEvictableIdleTimeMillis) Parameters: testWhileIdle - whether or not to validate objects in the idle object eviction thread, if any (see GenericKeyedObjectPool.setTestWhileIdle) |
GenericKeyedObjectPool | public GenericKeyedObjectPool(KeyedPoolableObjectFactory factory, int maxActive, byte whenExhaustedAction, long maxWait, int maxIdle, int maxTotal, int minIdle, boolean testOnBorrow, boolean testOnReturn, long timeBetweenEvictionRunsMillis, int numTestsPerEvictionRun, long minEvictableIdleTimeMillis, boolean testWhileIdle)(Code) | | Create a new GenericKeyedObjectPool using the specified values.
Parameters: factory - the (possibly null)PoolableObjectFactory to use to create, validate and destroy objects Parameters: maxActive - the maximum number of objects that can be borrowed from me at one time (per key) (see GenericKeyedObjectPool.setMaxActive) Parameters: whenExhaustedAction - the action to take when the pool is exhausted (see GenericKeyedObjectPool.setWhenExhaustedAction) Parameters: maxWait - the maximum amount of time to wait for an idle object when the pool is exhausted an and whenExhaustedAction is GenericKeyedObjectPool.WHEN_EXHAUSTED_BLOCK (otherwise ignored) (see GenericKeyedObjectPool.setMaxWait) Parameters: maxIdle - the maximum number of idle objects in my pool (see GenericKeyedObjectPool.setMaxIdle) Parameters: maxTotal - the maximum number of objects that can exists at one time (see GenericKeyedObjectPool.setMaxTotal) Parameters: minIdle - the minimum number of idle objects to have in the pool at any one time (see GenericKeyedObjectPool.setMinIdle) Parameters: testOnBorrow - whether or not to validate objects before they are returned by the GenericKeyedObjectPool.borrowObject method (see GenericKeyedObjectPool.setTestOnBorrow) Parameters: testOnReturn - whether or not to validate objects after they are returned to the GenericKeyedObjectPool.returnObject method (see GenericKeyedObjectPool.setTestOnReturn) Parameters: timeBetweenEvictionRunsMillis - the amount of time (in milliseconds) to sleep between examining idle objects for eviction (see GenericKeyedObjectPool.setTimeBetweenEvictionRunsMillis) Parameters: numTestsPerEvictionRun - the number of idle objects to examine per run within the idle object eviction thread (if any) (see GenericKeyedObjectPool.setNumTestsPerEvictionRun) Parameters: minEvictableIdleTimeMillis - the minimum number of milliseconds an object can sit idle in the pool before it is eligable for evcition (see GenericKeyedObjectPool.setMinEvictableIdleTimeMillis) Parameters: testWhileIdle - whether or not to validate objects in the idle object eviction thread, if any (see GenericKeyedObjectPool.setTestWhileIdle) |
clear | public synchronized void clear()(Code) | | |
clearOldest | public synchronized void clearOldest()(Code) | | Method clears oldest 15% of objects in pool. The method sorts the
objects into a TreeMap and then iterates the first 15% for removal
|
getMaxActive | public synchronized int getMaxActive()(Code) | | Returns the cap on the number of active instances from my pool (per key).
the cap on the number of active instances from my pool (per key). See Also: GenericKeyedObjectPool.setMaxActive |
getMaxIdle | public synchronized int getMaxIdle()(Code) | | Returns the cap on the number of "idle" instances in the pool.
the cap on the number of "idle" instances in the pool. See Also: GenericKeyedObjectPool.setMaxIdle |
getMaxTotal | public synchronized int getMaxTotal()(Code) | | Returns the cap on the total number of instances from my pool if non-positive.
the cap on the total number of instances from my pool if non-positive. See Also: GenericKeyedObjectPool.setMaxTotal |
getMinIdle | public synchronized int getMinIdle()(Code) | | Returns the minimum number of idle objects in pool to maintain (per key)
the minimum number of idle objects in pool to maintain (per key) See Also: GenericKeyedObjectPool.setMinIdle |
getNumActive | public synchronized int getNumActive()(Code) | | |
getNumActive | public synchronized int getNumActive(Object key)(Code) | | |
getNumIdle | public synchronized int getNumIdle()(Code) | | |
getNumIdle | public synchronized int getNumIdle(Object key)(Code) | | |
getTimeBetweenEvictionRunsMillis | public synchronized long getTimeBetweenEvictionRunsMillis()(Code) | | 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.
See Also: GenericKeyedObjectPool.setTimeBetweenEvictionRunsMillis |
preparePool | public synchronized void preparePool(Object key, boolean populateImmediately)(Code) | | Registers a key for pool control.
If populateImmediately is true , the pool will immediately commence
a sustain cycle. If populateImmediately is false , the pool will be
populated when the next schedules sustain task is run.
Parameters: key - - The key to register for pool control. Parameters: populateImmediately - - If this is true , the poolwill start a sustain cycle immediately. |
setMaxActive | public synchronized void setMaxActive(int maxActive)(Code) | | Sets the cap on the number of active instances from my pool (per key).
Parameters: maxActive - The cap on the number of active instances from my pool (per key).Use a negative value for an infinite number of instances. See Also: GenericKeyedObjectPool.getMaxActive |
setMaxIdle | public synchronized void setMaxIdle(int maxIdle)(Code) | | Sets the cap on the number of "idle" instances in the pool.
Parameters: maxIdle - The cap on the number of "idle" instances in the pool.Use a negative value to indicate an unlimited numberof idle instances. See Also: GenericKeyedObjectPool.getMaxIdle |
setMaxTotal | public synchronized void setMaxTotal(int maxTotal)(Code) | | Sets the cap on the total number of instances from my pool if non-positive.
Parameters: maxTotal - The cap on the total number of instances from my pool.Use a non-positive value for an infinite number of instances. See Also: GenericKeyedObjectPool.getMaxTotal |
setMinIdle | public synchronized void setMinIdle(int poolSize)(Code) | | Sets the minimum number of idle objects in pool to maintain (per key)
Parameters: poolSize - - The minimum size of the pool See Also: GenericKeyedObjectPool.getMinIdle |
setTimeBetweenEvictionRunsMillis | public synchronized void setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis)(Code) | | 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.
See Also: GenericKeyedObjectPool.getTimeBetweenEvictionRunsMillis |
startEvictor | protected synchronized void startEvictor(long delay)(Code) | | Start the eviction thread or service, or when
delay is non-positive, stop it
if it is already running.
|
|
|