|
|||||||||
| Home >> All >> org >> apache >> commons >> pool >> [ impl overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
org.apache.commons.pool.impl
Class GenericKeyedObjectPool

java.lang.Objectorg.apache.commons.pool.BaseKeyedObjectPool
org.apache.commons.pool.impl.GenericKeyedObjectPool
- All Implemented Interfaces:
- org.apache.commons.pool.KeyedObjectPool
- public class GenericKeyedObjectPool
- extends org.apache.commons.pool.BaseKeyedObjectPool
- implements org.apache.commons.pool.KeyedObjectPool
- extends org.apache.commons.pool.BaseKeyedObjectPool
A configurable org.apache.commons.pool.KeyedObjectPool implementation.
When coupled with the appropriate org.apache.commons.pool.KeyedPoolableObjectFactory, GenericKeyedObjectPool provides robust pooling functionality for arbitrary objects.
A GenericKeyedObjectPool provides a number of configurable parameters:
- maxActive 55 controls the maximum number of objects (per key) that can be borrowed from the pool at one time. When non-positive, there is no limit to the number of objects that may be active at one time. When maxActive 55 is exceeded, the pool is said to be exhausted.
- maxIdle 55 controls the maximum number of objects that can sit idle in the pool (per key) at any time. When negative, there is no limit to the number of objects that may be idle at one time.
-
whenExhaustedAction 55 specifies the
behaviour of the
borrowObject(java.lang.Object)55 method when the pool is exhausted:-
When whenExhaustedAction 55 is
WHEN_EXHAUSTED_FAIL55 ,borrowObject(java.lang.Object)55 will throw a java.util.NoSuchElementException -
When whenExhaustedAction 55 is
WHEN_EXHAUSTED_GROW55 ,borrowObject(java.lang.Object)55 will create a new object and return it(essentially making maxActive 55 meaningless.) -
When whenExhaustedAction 55
is
WHEN_EXHAUSTED_BLOCK55 ,borrowObject(java.lang.Object)55 will block (invoke Object.wait()>Object.wait()55 until a new or idle object is available. If a positive maxWait 55 value is supplied, theborrowObject(java.lang.Object)55 will block for at most that many milliseconds, after which a java.util.NoSuchElementException will be thrown. If maxWait 55 is non-positive, theborrowObject(java.lang.Object)55 method will block indefinitely.
-
When whenExhaustedAction 55 is
-
When testOnBorrow 55 is set, the pool will
attempt to validate each object before it is returned from the
borrowObject(java.lang.Object)55 method. (Using the provided factory's PoolableObjectFactory.validateObject(java.lang.Object)>PoolableObjectFactory.validateObject(java.lang.Object)55 method.) Objects that fail to validate will be dropped from the pool, and a different object will be borrowed. -
When testOnReturn 55 is set, the pool will
attempt to validate each object before it is returned to the pool in the
returnObject(java.lang.Object, java.lang.Object)55 method. (Using the provided factory's PoolableObjectFactory.validateObject(java.lang.Object)>PoolableObjectFactory.validateObject(java.lang.Object)55 method.) Objects that fail to validate will be dropped from the pool.
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:
- timeBetweenEvictionRunsMillis 55 indicates how long the eviction thread should sleep before "runs" of examining idle objects. When non-positive, no eviction thread will be launched.
- minEvictableIdleTimeMillis 55 specifies the minimum amount of time that an object may sit idle in the pool before it is eligable for eviction due to idle time. When non-positive, no object will be dropped from the pool due to idle time alone.
-
testWhileIdle 55 indicates whether or not idle
objects should be validated using the factory's
PoolableObjectFactory.validateObject(java.lang.Object)>
PoolableObjectFactory.validateObject(java.lang.Object)55 method. Objects that fail to validate will be dropped from the pool.
GenericKeyedObjectPool is not usable without a org.apache.commons.pool.KeyedPoolableObjectFactory. A
non-null factory must be provided either as a constructor argument
or via a call to setFactory(org.apache.commons.pool.KeyedPoolableObjectFactory) 55 before the pool is used.
- Version:
- $Revision: 1.26 $ $Date: 2004/02/28 11:46:33 $
| Nested Class Summary | |
static class |
GenericKeyedObjectPool.Config
A simple "struct" encapsulating the configuration information for a GenericKeyedObjectPool. |
(package private) class |
GenericKeyedObjectPool.Evictor
The idle object evictor thread. |
(package private) class |
GenericKeyedObjectPool.ObjectTimestampPair
A simple "struct" encapsulating an object instance and a timestamp. |
| Field Summary | |
private java.util.HashMap |
_activeMap
Count of active objects, per key. |
private org.apache.commons.collections.CursorableLinkedList.Cursor |
_evictionCursor
|
private org.apache.commons.collections.CursorableLinkedList.Cursor |
_evictionKeyCursor
|
private GenericKeyedObjectPool.Evictor |
_evictor
My idle object eviction thread, if any. |
private org.apache.commons.pool.KeyedPoolableObjectFactory |
_factory
My org.apache.commons.pool.KeyedPoolableObjectFactory. |
private int |
_maxActive
The cap on the number of active instances from the pool (per key). |
private int |
_maxIdle
The cap on the number of idle instances in the pool (per key). |
private int |
_maxTotal
The cap on the total number of instances from the pool. |
private long |
_maxWait
The maximum amount of time (in millis) the borrowObject(java.lang.Object) 55 method should block before throwing
an exception when the pool is exhausted and the
"when exhausted" action 55 is
WHEN_EXHAUSTED_BLOCK 55 . |
private long |
_minEvictableIdleTimeMillis
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). |
private int |
_numTestsPerEvictionRun
The number of objects to examine during each run of the idle object evictor thread (if any). |
private org.apache.commons.collections.CursorableLinkedList |
_poolList
A cursorable list of my pools. |
private java.util.HashMap |
_poolMap
My hash of pools (CursorableLinkedLists). |
private boolean |
_testOnBorrow
When true, objects will be validated 55 before being returned by the borrowObject(java.lang.Object) 55
method. |
private boolean |
_testOnReturn
When true, objects will be validated 55 before being returned to the pool within the returnObject(java.lang.Object, java.lang.Object) 55 . |
private boolean |
_testWhileIdle
When true, objects will be validated 55 by the idle object evictor (if any). |
private long |
_timeBetweenEvictionRunsMillis
The number of milliseconds to sleep between runs of the idle object evictor thread. |
private int |
_totalActive
The total number of active instances. |
private int |
_totalIdle
The total number of idle instances. |
private byte |
_whenExhaustedAction
The action to take when the borrowObject(java.lang.Object) 55 method
is invoked when the pool is exhausted (the maximum number
of "active" objects has been reached). |
static int |
DEFAULT_MAX_ACTIVE
The default cap on the total number of active instances from the pool (per key). |
static int |
DEFAULT_MAX_IDLE
The default cap on the number of idle instances in the pool (per key). |
static int |
DEFAULT_MAX_TOTAL
The default cap on the the maximum number of objects that can exists at one time. |
static long |
DEFAULT_MAX_WAIT
The default maximum amount of time (in millis) the borrowObject(java.lang.Object) 55 method should block before throwing
an exception when the pool is exhausted and the
"when exhausted" action 55 is
WHEN_EXHAUSTED_BLOCK 55 . |
static long |
DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS
The default value for getMinEvictableIdleTimeMillis() 55 . |
static int |
DEFAULT_NUM_TESTS_PER_EVICTION_RUN
The default number of objects to examine per run in the idle object evictor. |
static boolean |
DEFAULT_TEST_ON_BORROW
The default "test on borrow" value. |
static boolean |
DEFAULT_TEST_ON_RETURN
The default "test on return" value. |
static boolean |
DEFAULT_TEST_WHILE_IDLE
The default "test while idle" value. |
static long |
DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS
The default "time between eviction runs" value. |
static byte |
DEFAULT_WHEN_EXHAUSTED_ACTION
The default "when exhausted action" for the pool. |
static 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(java.lang.Object) 55
method should block until a new object is available, or the
maximum wait time 55 has been reached. |
static 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(java.lang.Object) 55
method should fail, throwing a java.util.NoSuchElementException. |
static 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(java.lang.Object) 55
method should simply create a new object anyway. |
| Constructor Summary | |
GenericKeyedObjectPool()
Create a new GenericKeyedObjectPool.. |
|
GenericKeyedObjectPool(org.apache.commons.pool.KeyedPoolableObjectFactory factory)
Create a new GenericKeyedObjectPool using the specified values. |
|
GenericKeyedObjectPool(org.apache.commons.pool.KeyedPoolableObjectFactory factory,
GenericKeyedObjectPool.Config config)
Create a new GenericKeyedObjectPool using the specified values. |
|
GenericKeyedObjectPool(org.apache.commons.pool.KeyedPoolableObjectFactory factory,
int maxActive)
Create a new GenericKeyedObjectPool using the specified values. |
|
GenericKeyedObjectPool(org.apache.commons.pool.KeyedPoolableObjectFactory factory,
int maxActive,
byte whenExhaustedAction,
long maxWait)
Create a new GenericKeyedObjectPool using the specified values. |
|
GenericKeyedObjectPool(org.apache.commons.pool.KeyedPoolableObjectFactory factory,
int maxActive,
byte whenExhaustedAction,
long maxWait,
boolean testOnBorrow,
boolean testOnReturn)
Create a new GenericKeyedObjectPool using the specified values. |
|
GenericKeyedObjectPool(org.apache.commons.pool.KeyedPoolableObjectFactory factory,
int maxActive,
byte whenExhaustedAction,
long maxWait,
int maxIdle)
Create a new GenericKeyedObjectPool using the specified values. |
|
GenericKeyedObjectPool(org.apache.commons.pool.KeyedPoolableObjectFactory factory,
int maxActive,
byte whenExhaustedAction,
long maxWait,
int maxIdle,
boolean testOnBorrow,
boolean testOnReturn)
Create a new GenericKeyedObjectPool using the specified values. |
|
GenericKeyedObjectPool(org.apache.commons.pool.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. |
|
GenericKeyedObjectPool(org.apache.commons.pool.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. |
|
| Method Summary | |
void |
addObject(java.lang.Object key)
Create an object using my factory 55 or other implementation dependent mechanism, and place it into the pool. |
java.lang.Object |
borrowObject(java.lang.Object key)
Obtain an instance from my pool for the specified key. |
void |
clear()
Clears my pool, removing all pooled instances (optional operation). |
void |
clear(java.lang.Object key)
Clears the specified pool, removing all pooled instances corresponding to the given key (optional operation). |
void |
close()
Close this pool, and free any resources associated with it. |
(package private) java.lang.String |
debugInfo()
|
private void |
decrementActiveCount(java.lang.Object key)
|
void |
evict()
|
private int |
getActiveCount(java.lang.Object key)
|
int |
getMaxActive()
Returns the cap on the number of active instances from my pool (per key). |
int |
getMaxIdle()
Returns the cap on the number of "idle" instances in the pool. |
int |
getMaxTotal()
Returns the cap on the total number of instances from my pool. |
long |
getMaxWait()
Returns the maximum amount of time (in milliseconds) the borrowObject(java.lang.Object) 55 method should block before throwing
an exception when the pool is exhausted and the
"when exhausted" action 55 is
WHEN_EXHAUSTED_BLOCK 55 . |
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). |
int |
getNumActive()
Returns the total number of instances current borrowed from my pool but not yet returned (optional operation). |
int |
getNumActive(java.lang.Object key)
Returns the number of instances currently borrowed from but not yet returned to my pool corresponding to the given key (optional operation). |
int |
getNumIdle()
Returns the total number of instances currently idle in my pool (optional operation). |
int |
getNumIdle(java.lang.Object key)
Returns the number of instances corresponding to the given key currently idle in my pool (optional operation). |
private int |
getNumTests()
|
int |
getNumTestsPerEvictionRun()
Returns the number of objects to examine during each run of the idle object evictor thread (if any). |
boolean |
getTestOnBorrow()
When true, objects will be validated 55 before being returned by the borrowObject(java.lang.Object) 55
method. |
boolean |
getTestOnReturn()
When true, objects will be validated 55 before being returned to the pool within the returnObject(java.lang.Object, java.lang.Object) 55 . |
boolean |
getTestWhileIdle()
When true, objects will be validated 55 by the idle object evictor (if any). |
long |
getTimeBetweenEvictionRunsMillis()
Returns the number of milliseconds to sleep between runs of the idle object evictor thread. |
byte |
getWhenExhaustedAction()
Returns the action to take when the borrowObject(java.lang.Object) 55 method
is invoked when the pool is exhausted (the maximum number
of "active" objects has been reached). |
private void |
incrementActiveCount(java.lang.Object key)
|
void |
invalidateObject(java.lang.Object key,
java.lang.Object obj)
Invalidates an object from the pool By contract, obj MUST have been obtained using borrowObject 55 or a related method as defined in an implementation or sub-interface using a key that is equivalent to the one used to borrow the Object in the first place. |
void |
returnObject(java.lang.Object key,
java.lang.Object obj)
Return an instance to my pool. |
void |
setConfig(GenericKeyedObjectPool.Config conf)
Sets my configuration. |
void |
setFactory(org.apache.commons.pool.KeyedPoolableObjectFactory factory)
Sets the factory I use to create new instances (optional operation). |
void |
setMaxActive(int maxActive)
Sets the cap on the number of active instances from my pool (per key). |
void |
setMaxIdle(int maxIdle)
Sets the cap on the number of "idle" instances in the pool. |
void |
setMaxTotal(int maxTotal)
Sets the cap on the total number of instances from my pool. |
void |
setMaxWait(long maxWait)
Sets the maximum amount of time (in milliseconds) the borrowObject(java.lang.Object) 55 method should block before throwing
an exception when the pool is exhausted and the
"when exhausted" action 55 is
WHEN_EXHAUSTED_BLOCK 55 . |
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). |
void |
setNumTestsPerEvictionRun(int numTestsPerEvictionRun)
Sets the number of objects to examine during each run of the idle object evictor thread (if any). |
void |
setTestOnBorrow(boolean testOnBorrow)
When true, objects will be validated 55 before being returned by the borrowObject(java.lang.Object) 55
method. |
void |
setTestOnReturn(boolean testOnReturn)
When true, objects will be validated 55 before being returned to the pool within the returnObject(java.lang.Object, java.lang.Object) 55 . |
void |
setTestWhileIdle(boolean testWhileIdle)
When true, objects will be validated 55 by the idle object evictor (if any). |
void |
setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis)
Sets the number of milliseconds to sleep between runs of the idle object evictor thread. |
void |
setWhenExhaustedAction(byte whenExhaustedAction)
Sets the action to take when the borrowObject(java.lang.Object) 55 method
is invoked when the pool is exhausted (the maximum number
of "active" objects has been reached). |
protected void |
startEvictor(long delay)
Start the eviction thread or service, or when delay is non-positive, stop it if it is already running. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
WHEN_EXHAUSTED_FAIL
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(java.lang.Object)55 method should fail, throwing a java.util.NoSuchElementException.- See Also:
WHEN_EXHAUSTED_BLOCK55 ,WHEN_EXHAUSTED_GROW55 ,setWhenExhaustedAction(byte)55 , Constant Field Values
WHEN_EXHAUSTED_BLOCK
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(java.lang.Object)55 method should block until a new object is available, or the maximum wait time 55 has been reached.- See Also:
WHEN_EXHAUSTED_FAIL55 ,WHEN_EXHAUSTED_GROW55 ,setMaxWait(long)55 ,getMaxWait()55 ,setWhenExhaustedAction(byte)55 , Constant Field Values
WHEN_EXHAUSTED_GROW
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(java.lang.Object)55 method should simply create a new object anyway.- See Also:
WHEN_EXHAUSTED_FAIL55 ,WHEN_EXHAUSTED_GROW55 ,setWhenExhaustedAction(byte)55 , Constant Field Values
DEFAULT_MAX_IDLE
public static final int DEFAULT_MAX_IDLE
- The default cap on the number of idle instances in the pool
(per key).
- See Also:
getMaxIdle()55 ,setMaxIdle(int)55 , Constant Field Values
DEFAULT_MAX_ACTIVE
public static final int DEFAULT_MAX_ACTIVE
- The default cap on the total number of active instances from the pool
(per key).
- See Also:
getMaxActive()55 ,setMaxActive(int)55 , Constant Field Values
DEFAULT_MAX_TOTAL
public static final int DEFAULT_MAX_TOTAL
- The default cap on the the maximum number of objects that can exists at one time.
- See Also:
getMaxTotal()55 ,setMaxTotal(int)55 , Constant Field Values
DEFAULT_WHEN_EXHAUSTED_ACTION
public static final byte DEFAULT_WHEN_EXHAUSTED_ACTION
- The default "when exhausted action" for the pool.
- See Also:
WHEN_EXHAUSTED_BLOCK55 ,WHEN_EXHAUSTED_FAIL55 ,WHEN_EXHAUSTED_GROW55 ,setWhenExhaustedAction(byte)55 , Constant Field Values
DEFAULT_MAX_WAIT
public static final long DEFAULT_MAX_WAIT
- The default maximum amount of time (in millis) the
borrowObject(java.lang.Object)55 method should block before throwing an exception when the pool is exhausted and the "when exhausted" action 55 isWHEN_EXHAUSTED_BLOCK55 .- See Also:
getMaxWait()55 ,setMaxWait(long)55 , Constant Field Values
DEFAULT_TEST_ON_BORROW
public static final boolean DEFAULT_TEST_ON_BORROW
- The default "test on borrow" value.
- See Also:
getTestOnBorrow()55 ,setTestOnBorrow(boolean)55 , Constant Field Values
DEFAULT_TEST_ON_RETURN
public static final boolean DEFAULT_TEST_ON_RETURN
- The default "test on return" value.
- See Also:
getTestOnReturn()55 ,setTestOnReturn(boolean)55 , Constant Field Values
DEFAULT_TEST_WHILE_IDLE
public static final boolean DEFAULT_TEST_WHILE_IDLE
- The default "test while idle" value.
DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS
public static final long DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS
- The default "time between eviction runs" value.
DEFAULT_NUM_TESTS_PER_EVICTION_RUN
public static final int DEFAULT_NUM_TESTS_PER_EVICTION_RUN
- The default number of objects to examine per run in the
idle object evictor.
DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS
public static final long DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS
- The default value for
getMinEvictableIdleTimeMillis()55 .
_maxIdle
private int _maxIdle
- The cap on the number of idle instances in the pool (per key).
- See Also:
setMaxIdle(int)55 ,getMaxIdle()55
_maxActive
private int _maxActive
- The cap on the number of active instances from the pool (per key).
- See Also:
setMaxActive(int)55 ,getMaxActive()55
_maxTotal
private int _maxTotal
- The cap on the total number of instances from the pool.
- See Also:
setMaxTotal(int)55 ,getMaxTotal()55
_maxWait
private long _maxWait
- The maximum amount of time (in millis) the
borrowObject(java.lang.Object)55 method should block before throwing an exception when the pool is exhausted and the "when exhausted" action 55 isWHEN_EXHAUSTED_BLOCK55 . When less than 0, theborrowObject(java.lang.Object)55 method may block indefinitely.- See Also:
setMaxWait(long)55 ,getMaxWait()55 ,WHEN_EXHAUSTED_BLOCK55 ,setWhenExhaustedAction(byte)55 ,getWhenExhaustedAction()55
_whenExhaustedAction
private byte _whenExhaustedAction
- The action to take when the
borrowObject(java.lang.Object)55 method is invoked when the pool is exhausted (the maximum number of "active" objects has been reached).- See Also:
WHEN_EXHAUSTED_BLOCK55 ,WHEN_EXHAUSTED_FAIL55 ,WHEN_EXHAUSTED_GROW55 ,DEFAULT_WHEN_EXHAUSTED_ACTION55 ,setWhenExhaustedAction(byte)55 ,getWhenExhaustedAction()55
_testOnBorrow
private boolean _testOnBorrow
- When true, objects will be
validated 55
before being returned by the
borrowObject(java.lang.Object)55 method. If the object fails to validate, it will be dropped from the pool, and we will attempt to borrow another.- See Also:
setTestOnBorrow(boolean)55 ,getTestOnBorrow()55
_testOnReturn
private boolean _testOnReturn
- When true, objects will be
validated 55
before being returned to the pool within the
returnObject(java.lang.Object, java.lang.Object)55 .- See Also:
getTestOnReturn()55 ,setTestOnReturn(boolean)55
_testWhileIdle
private boolean _testWhileIdle
- When true, objects will be
validated 55
by the idle object evictor (if any). If an object
fails to validate, it will be dropped from the pool.
- See Also:
setTestWhileIdle(boolean)55 ,getTestWhileIdle()55 ,getTimeBetweenEvictionRunsMillis()55 ,setTimeBetweenEvictionRunsMillis(long)55
_timeBetweenEvictionRunsMillis
private long _timeBetweenEvictionRunsMillis
- 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:
setTimeBetweenEvictionRunsMillis(long)55 ,getTimeBetweenEvictionRunsMillis()55
_numTestsPerEvictionRun
private int _numTestsPerEvictionRun
- The number of objects to examine during each run of the
idle object evictor thread (if any).
When a negative value is supplied, ceil(
getNumIdle()55 )/abs(getNumTestsPerEvictionRun()55 ) tests will be run. I.e., when the value is -n, roughly one nth of the idle objects will be tested per run.
_minEvictableIdleTimeMillis
private long _minEvictableIdleTimeMillis
- 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).
When non-positive, no objects will be evicted from the pool
due to idle time alone.
_poolMap
private java.util.HashMap _poolMap
- My hash of pools (CursorableLinkedLists).
_poolList
private org.apache.commons.collections.CursorableLinkedList _poolList
- A cursorable list of my pools.
- See Also:
GenericKeyedObjectPool.Evictor.run()55
_activeMap
private java.util.HashMap _activeMap
- Count of active objects, per key.
_totalActive
private int _totalActive
- The total number of active instances.
_totalIdle
private int _totalIdle
- The total number of idle instances.
_factory
private org.apache.commons.pool.KeyedPoolableObjectFactory _factory
_evictor
private GenericKeyedObjectPool.Evictor _evictor
- My idle object eviction thread, if any.
_evictionCursor
private org.apache.commons.collections.CursorableLinkedList.Cursor _evictionCursor
_evictionKeyCursor
private org.apache.commons.collections.CursorableLinkedList.Cursor _evictionKeyCursor
| Constructor Detail |
GenericKeyedObjectPool
public GenericKeyedObjectPool()
- Create a new GenericKeyedObjectPool..
GenericKeyedObjectPool
public GenericKeyedObjectPool(org.apache.commons.pool.KeyedPoolableObjectFactory factory)
- Create a new GenericKeyedObjectPool using the specified values.
GenericKeyedObjectPool
public GenericKeyedObjectPool(org.apache.commons.pool.KeyedPoolableObjectFactory factory, GenericKeyedObjectPool.Config config)
- Create a new GenericKeyedObjectPool using the specified values.
GenericKeyedObjectPool
public GenericKeyedObjectPool(org.apache.commons.pool.KeyedPoolableObjectFactory factory, int maxActive)
- Create a new GenericKeyedObjectPool using the specified values.
GenericKeyedObjectPool
public GenericKeyedObjectPool(org.apache.commons.pool.KeyedPoolableObjectFactory factory, int maxActive, byte whenExhaustedAction, long maxWait)
- Create a new GenericKeyedObjectPool using the specified values.
GenericKeyedObjectPool
public GenericKeyedObjectPool(org.apache.commons.pool.KeyedPoolableObjectFactory factory, int maxActive, byte whenExhaustedAction, long maxWait, boolean testOnBorrow, boolean testOnReturn)
- Create a new GenericKeyedObjectPool using the specified values.
GenericKeyedObjectPool
public GenericKeyedObjectPool(org.apache.commons.pool.KeyedPoolableObjectFactory factory, int maxActive, byte whenExhaustedAction, long maxWait, int maxIdle)
- Create a new GenericKeyedObjectPool using the specified values.
GenericKeyedObjectPool
public GenericKeyedObjectPool(org.apache.commons.pool.KeyedPoolableObjectFactory factory, int maxActive, byte whenExhaustedAction, long maxWait, int maxIdle, boolean testOnBorrow, boolean testOnReturn)
- Create a new GenericKeyedObjectPool using the specified values.
GenericKeyedObjectPool
public GenericKeyedObjectPool(org.apache.commons.pool.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.
GenericKeyedObjectPool
public GenericKeyedObjectPool(org.apache.commons.pool.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.
| Method Detail |
getMaxActive
public int getMaxActive()
- Returns the cap on the number of active instances from my pool (per key).
setMaxActive
public void setMaxActive(int maxActive)
- Sets the cap on the number of active instances from my pool (per key).
getMaxTotal
public int getMaxTotal()
- Returns the cap on the total number of instances from my pool.
setMaxTotal
public void setMaxTotal(int maxTotal)
- Sets the cap on the total number of instances from my pool.
getWhenExhaustedAction
public byte getWhenExhaustedAction()
- Returns the action to take when the
borrowObject(java.lang.Object)55 method is invoked when the pool is exhausted (the maximum number of "active" objects has been reached).
setWhenExhaustedAction
public void setWhenExhaustedAction(byte whenExhaustedAction)
- Sets the action to take when the
borrowObject(java.lang.Object)55 method is invoked when the pool is exhausted (the maximum number of "active" objects has been reached).
getMaxWait
public long getMaxWait()
- Returns the maximum amount of time (in milliseconds) the
borrowObject(java.lang.Object)55 method should block before throwing an exception when the pool is exhausted and the "when exhausted" action 55 isWHEN_EXHAUSTED_BLOCK55 . When less than 0, theborrowObject(java.lang.Object)55 method may block indefinitely.
setMaxWait
public void setMaxWait(long maxWait)
- Sets the maximum amount of time (in milliseconds) the
borrowObject(java.lang.Object)55 method should block before throwing an exception when the pool is exhausted and the "when exhausted" action 55 isWHEN_EXHAUSTED_BLOCK55 . When less than 0, theborrowObject(java.lang.Object)55 method may block indefinitely.
getMaxIdle
public int getMaxIdle()
- Returns the cap on the number of "idle" instances in the pool.
setMaxIdle
public void setMaxIdle(int maxIdle)
- Sets the cap on the number of "idle" instances in the pool.
getTestOnBorrow
public boolean getTestOnBorrow()
- When true, objects will be
validated 55
before being returned by the
borrowObject(java.lang.Object)55 method. If the object fails to validate, it will be dropped from the pool, and we will attempt to borrow another.
setTestOnBorrow
public void setTestOnBorrow(boolean testOnBorrow)
- When true, objects will be
validated 55
before being returned by the
borrowObject(java.lang.Object)55 method. If the object fails to validate, it will be dropped from the pool, and we will attempt to borrow another.
getTestOnReturn
public boolean getTestOnReturn()
- When true, objects will be
validated 55
before being returned to the pool within the
returnObject(java.lang.Object, java.lang.Object)55 .
setTestOnReturn
public void setTestOnReturn(boolean testOnReturn)
- When true, objects will be
validated 55
before being returned to the pool within the
returnObject(java.lang.Object, java.lang.Object)55 .
getTimeBetweenEvictionRunsMillis
public 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.
setTimeBetweenEvictionRunsMillis
public 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.
getNumTestsPerEvictionRun
public int getNumTestsPerEvictionRun()
- Returns the number of objects to examine during each run of the
idle object evictor thread (if any).
setNumTestsPerEvictionRun
public 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(
getNumIdle()55 )/abs(getNumTestsPerEvictionRun()55 ) tests will be run. I.e., when the value is -n, roughly one nth of the idle objects will be tested per run.
getMinEvictableIdleTimeMillis
public 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).
setMinEvictableIdleTimeMillis
public 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).
When non-positive, no objects will be evicted from the pool
due to idle time alone.
getTestWhileIdle
public boolean getTestWhileIdle()
- When true, objects will be
validated 55
by the idle object evictor (if any). If an object
fails to validate, it will be dropped from the pool.
setTestWhileIdle
public void setTestWhileIdle(boolean testWhileIdle)
- When true, objects will be
validated 55
by the idle object evictor (if any). If an object
fails to validate, it will be dropped from the pool.
setConfig
public void setConfig(GenericKeyedObjectPool.Config conf)
- Sets my configuration.
borrowObject
public java.lang.Object borrowObject(java.lang.Object key) throws java.lang.Exception
- Description copied from interface:
org.apache.commons.pool.KeyedObjectPool - Obtain an instance from my pool
for the specified key.
By contract, clients MUST return
the borrowed object using
returnObject>returnObject 55 ,
or a related method as defined in an implementation
or sub-interface,
using a key that is equivalent to the one used to
borrow the instance in the first place.
- Specified by:
borrowObjectin interfaceorg.apache.commons.pool.KeyedObjectPool
clear
public void clear()
- Description copied from interface:
org.apache.commons.pool.KeyedObjectPool - Clears my pool, removing all pooled instances
(optional operation).
Throws java.lang.UnsupportedOperationException
if the pool cannot be cleared.
- Specified by:
clearin interfaceorg.apache.commons.pool.KeyedObjectPool
clear
public void clear(java.lang.Object key)
- Description copied from interface:
org.apache.commons.pool.KeyedObjectPool - Clears the specified pool, removing all
pooled instances corresponding to
the given key (optional operation).
Throws java.lang.UnsupportedOperationException
if the pool cannot be cleared.
- Specified by:
clearin interfaceorg.apache.commons.pool.KeyedObjectPool
getNumActive
public int getNumActive()
- Description copied from interface:
org.apache.commons.pool.KeyedObjectPool - Returns the total number of instances
current borrowed from my pool but not
yet returned (optional operation).
Throws java.lang.UnsupportedOperationException
if this information is not available.
- Specified by:
getNumActivein interfaceorg.apache.commons.pool.KeyedObjectPool
getNumIdle
public int getNumIdle()
- Description copied from interface:
org.apache.commons.pool.KeyedObjectPool - Returns the total number of instances
currently idle in my pool (optional operation).
Throws java.lang.UnsupportedOperationException
if this information is not available.
- Specified by:
getNumIdlein interfaceorg.apache.commons.pool.KeyedObjectPool
getNumActive
public int getNumActive(java.lang.Object key)
- Description copied from interface:
org.apache.commons.pool.KeyedObjectPool - Returns the number of instances
currently borrowed from but not yet returned
to my pool corresponding to the
given key (optional operation).
Throws java.lang.UnsupportedOperationException
if this information is not available.
- Specified by:
getNumActivein interfaceorg.apache.commons.pool.KeyedObjectPool
getNumIdle
public int getNumIdle(java.lang.Object key)
- Description copied from interface:
org.apache.commons.pool.KeyedObjectPool - Returns the number of instances
corresponding to the given key
currently idle in my pool (optional operation).
Throws java.lang.UnsupportedOperationException
if this information is not available.
- Specified by:
getNumIdlein interfaceorg.apache.commons.pool.KeyedObjectPool
returnObject
public void returnObject(java.lang.Object key, java.lang.Object obj) throws java.lang.Exception
- Description copied from interface:
org.apache.commons.pool.KeyedObjectPool - Return an instance to my pool.
By contract, obj MUST have been obtained
using borrowObject>borrowObject 55
or a related method as defined in an implementation
or sub-interface
using a key that is equivalent to the one used to
borrow the Object in the first place.
- Specified by:
returnObjectin interfaceorg.apache.commons.pool.KeyedObjectPool
invalidateObject
public void invalidateObject(java.lang.Object key, java.lang.Object obj) throws java.lang.Exception
- Description copied from interface:
org.apache.commons.pool.KeyedObjectPool - Invalidates an object from the pool
By contract, obj MUST have been obtained
using borrowObject 55
or a related method as defined in an implementation
or sub-interface
using a key that is equivalent to the one used to
borrow the Object in the first place.
This method should be used when an object that has been borrowed is determined (due to an exception or other problem) to be invalid. If the connection should be validated before or after borrowing, then the PoolableObjectFactory.validateObject(java.lang.Object)>
PoolableObjectFactory.validateObject(java.lang.Object)55 method should be used instead.- Specified by:
invalidateObjectin interfaceorg.apache.commons.pool.KeyedObjectPool
addObject
public void addObject(java.lang.Object key) throws java.lang.Exception
- Description copied from interface:
org.apache.commons.pool.KeyedObjectPool - Create an object using my factory 55 or other
implementation dependent mechanism, and place it into the pool.
addObject() is useful for "pre-loading" a pool with idle objects.
(Optional operation).
- Specified by:
addObjectin interfaceorg.apache.commons.pool.KeyedObjectPool
close
public void close()
throws java.lang.Exception
- Description copied from interface:
org.apache.commons.pool.KeyedObjectPool - Close this pool, and free any resources associated with it.
- Specified by:
closein interfaceorg.apache.commons.pool.KeyedObjectPool
setFactory
public void setFactory(org.apache.commons.pool.KeyedPoolableObjectFactory factory) throws java.lang.IllegalStateException
- Description copied from interface:
org.apache.commons.pool.KeyedObjectPool - Sets the factory I use
to create new instances (optional operation).
- Specified by:
setFactoryin interfaceorg.apache.commons.pool.KeyedObjectPool
evict
public void evict()
throws java.lang.Exception
startEvictor
protected void startEvictor(long delay)
- Start the eviction thread or service, or when
delay is non-positive, stop it
if it is already running.
debugInfo
java.lang.String debugInfo()
getNumTests
private int getNumTests()
incrementActiveCount
private void incrementActiveCount(java.lang.Object key)
decrementActiveCount
private void decrementActiveCount(java.lang.Object key)
getActiveCount
private int getActiveCount(java.lang.Object key)
|
|||||||||
| Home >> All >> org >> apache >> commons >> pool >> [ impl overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC