|
|||||||||
| 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 GenericObjectPool

java.lang.Objectorg.apache.commons.pool.BaseObjectPool
org.apache.commons.pool.impl.GenericObjectPool
- All Implemented Interfaces:
- org.apache.commons.pool.ObjectPool
- public class GenericObjectPool
- extends org.apache.commons.pool.BaseObjectPool
- implements org.apache.commons.pool.ObjectPool
- extends org.apache.commons.pool.BaseObjectPool
A configurable org.apache.commons.pool.ObjectPool implementation.
When coupled with the appropriate org.apache.commons.pool.PoolableObjectFactory, GenericObjectPool provides robust pooling functionality for arbitrary objects.
A GenericObjectPool provides a number of configurable parameters:
- maxActive 55 controls the maximum number of objects 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 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()55 method when the pool is exhausted:-
When whenExhaustedAction 55 is
WHEN_EXHAUSTED_FAIL55 ,borrowObject()55 will throw a java.util.NoSuchElementException -
When whenExhaustedAction 55 is
WHEN_EXHAUSTED_GROW55 ,borrowObject()55 will create a new object and return it(essentially making maxActive 55 meaningless.) -
When whenExhaustedAction 55
is
WHEN_EXHAUSTED_BLOCK55 ,borrowObject()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()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()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()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)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.
GenericObjectPool is not usable without a org.apache.commons.pool.PoolableObjectFactory. A
non-null factory must be provided either as a constructor argument
or via a call to setFactory(org.apache.commons.pool.PoolableObjectFactory) 55 before the pool is used.
- Version:
- $Revision: 1.32 $ $Date: 2004/04/27 20:15:56 $
| Nested Class Summary | |
static class |
GenericObjectPool.Config
A simple "struct" encapsulating the configuration information for a GenericObjectPool. |
(package private) class |
GenericObjectPool.Evictor
The idle object evictor thread. |
(package private) class |
GenericObjectPool.ObjectTimestampPair
A simple "struct" encapsulating an object instance and a timestamp. |
| Field Summary | |
private org.apache.commons.collections.CursorableLinkedList.Cursor |
_evictionCursor
|
private GenericObjectPool.Evictor |
_evictor
My idle object eviction thread, if any. |
private org.apache.commons.pool.PoolableObjectFactory |
_factory
My org.apache.commons.pool.PoolableObjectFactory. |
private int |
_maxActive
The cap on the total number of active instances from the pool. |
private int |
_maxIdle
The cap on the number of idle instances in the pool. |
private long |
_maxWait
The maximum amount of time (in millis) the borrowObject() 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 |
_minIdle
The cap on the minimum number of idle instances in the pool. |
private int |
_numActive
The number of objects borrowObject() 55 borrowed
from the pool, but not yet returned. |
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 |
_pool
My pool. |
private boolean |
_testOnBorrow
When true, objects will be validated 55 before being returned by the borrowObject() 55
method. |
private boolean |
_testOnReturn
When true, objects will be validated 55 before being returned to the pool within the returnObject(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 byte |
_whenExhaustedAction
The action to take when the borrowObject() 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. |
static int |
DEFAULT_MAX_IDLE
The default cap on the number of "sleeping" instances in the pool. |
static long |
DEFAULT_MAX_WAIT
The default maximum amount of time (in millis) the borrowObject() 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_MIN_IDLE
The default minimum number of "sleeping" instances in the pool before before the evictor thread (if active) spawns new objects. |
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() 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() 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() 55
method should simply create a new object anyway. |
| Fields inherited from class org.apache.commons.pool.BaseObjectPool |
|
| Constructor Summary | |
GenericObjectPool()
Create a new GenericObjectPool. |
|
GenericObjectPool(org.apache.commons.pool.PoolableObjectFactory factory)
Create a new GenericObjectPool using the specified values. |
|
GenericObjectPool(org.apache.commons.pool.PoolableObjectFactory factory,
GenericObjectPool.Config config)
Create a new GenericObjectPool using the specified values. |
|
GenericObjectPool(org.apache.commons.pool.PoolableObjectFactory factory,
int maxActive)
Create a new GenericObjectPool using the specified values. |
|
GenericObjectPool(org.apache.commons.pool.PoolableObjectFactory factory,
int maxActive,
byte whenExhaustedAction,
long maxWait)
Create a new GenericObjectPool using the specified values. |
|
GenericObjectPool(org.apache.commons.pool.PoolableObjectFactory factory,
int maxActive,
byte whenExhaustedAction,
long maxWait,
boolean testOnBorrow,
boolean testOnReturn)
Create a new GenericObjectPool using the specified values. |
|
GenericObjectPool(org.apache.commons.pool.PoolableObjectFactory factory,
int maxActive,
byte whenExhaustedAction,
long maxWait,
int maxIdle)
Create a new GenericObjectPool using the specified values. |
|
GenericObjectPool(org.apache.commons.pool.PoolableObjectFactory factory,
int maxActive,
byte whenExhaustedAction,
long maxWait,
int maxIdle,
boolean testOnBorrow,
boolean testOnReturn)
Create a new GenericObjectPool using the specified values. |
|
GenericObjectPool(org.apache.commons.pool.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. |
|
GenericObjectPool(org.apache.commons.pool.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. |
|
| Method Summary | |
void |
addObject()
Create an object, and place it into the pool. |
private void |
addObjectToPool(java.lang.Object obj,
boolean decrementNumActive)
|
java.lang.Object |
borrowObject()
Obtain an instance from my pool. |
private int |
calculateDeficit()
|
void |
clear()
Clears any objects sitting idle in the pool, releasing any associated resources (optional operation). |
void |
close()
Close this pool, and free any resources associated with it. |
(package private) java.lang.String |
debugInfo()
|
private void |
ensureMinIdle()
Check to see if we are below our minimum number of objects if so enough to bring us back to our minimum. |
void |
evict()
|
int |
getMaxActive()
Returns the cap on the total number of active instances from my pool. |
int |
getMaxIdle()
Returns the cap on the number of "idle" instances in the pool. |
long |
getMaxWait()
Returns the maximum amount of time (in milliseconds) the borrowObject() 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 |
getMinIdle()
Returns the minimum number of objects allowed in the pool before the evictor thread (if active) spawns new objects. |
int |
getNumActive()
Return the number of instances currently borrowed from my pool (optional operation). |
int |
getNumIdle()
Return the number of instances 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() 55
method. |
boolean |
getTestOnReturn()
When true, objects will be validated 55 before being returned to the pool within the returnObject(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() 55 method
is invoked when the pool is exhausted (the maximum number
of "active" objects has been reached). |
void |
invalidateObject(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. |
void |
returnObject(java.lang.Object obj)
Return an instance to my pool. |
void |
setConfig(GenericObjectPool.Config conf)
Sets my configuration. |
void |
setFactory(org.apache.commons.pool.PoolableObjectFactory factory)
Sets the factory I use to create new instances (optional operation). |
void |
setMaxActive(int maxActive)
Sets the cap on the total number of active instances from my pool. |
void |
setMaxIdle(int maxIdle)
Sets the cap on the number of "idle" instances in the pool. |
void |
setMaxWait(long maxWait)
Sets the maximum amount of time (in milliseconds) the borrowObject() 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 |
setMinIdle(int minIdle)
Sets the minimum number of objects allowed in the pool before the evictor thread (if active) spawns new objects. |
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() 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) 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() 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 org.apache.commons.pool.BaseObjectPool |
assertOpen, isClosed |
| 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()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()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()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 "sleeping" instances in the pool.
- See Also:
getMaxIdle()55 ,setMaxIdle(int)55 , Constant Field Values
DEFAULT_MIN_IDLE
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.
- See Also:
getMinIdle()55 ,setMinIdle(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.
- See Also:
getMaxActive()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()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.
- See Also:
setMaxIdle(int)55 ,getMaxIdle()55
_minIdle
private int _minIdle
- The cap on the minimum number of idle instances in the pool.
- See Also:
setMinIdle(int)55 ,getMinIdle()55
_maxActive
private int _maxActive
- The cap on the total number of active instances from the pool.
- See Also:
setMaxActive(int)55 ,getMaxActive()55
_maxWait
private long _maxWait
- The maximum amount of time (in millis) the
borrowObject()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()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()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()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)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.
_pool
private org.apache.commons.collections.CursorableLinkedList _pool
- My pool.
_factory
private org.apache.commons.pool.PoolableObjectFactory _factory
_numActive
private int _numActive
- The number of objects
borrowObject()55 borrowed from the pool, but not yet returned.
_evictor
private GenericObjectPool.Evictor _evictor
- My idle object eviction thread, if any.
_evictionCursor
private org.apache.commons.collections.CursorableLinkedList.Cursor _evictionCursor
| Constructor Detail |
GenericObjectPool
public GenericObjectPool()
- Create a new GenericObjectPool.
GenericObjectPool
public GenericObjectPool(org.apache.commons.pool.PoolableObjectFactory factory)
- Create a new GenericObjectPool using the specified values.
GenericObjectPool
public GenericObjectPool(org.apache.commons.pool.PoolableObjectFactory factory, GenericObjectPool.Config config)
- Create a new GenericObjectPool using the specified values.
GenericObjectPool
public GenericObjectPool(org.apache.commons.pool.PoolableObjectFactory factory, int maxActive)
- Create a new GenericObjectPool using the specified values.
GenericObjectPool
public GenericObjectPool(org.apache.commons.pool.PoolableObjectFactory factory, int maxActive, byte whenExhaustedAction, long maxWait)
- Create a new GenericObjectPool using the specified values.
GenericObjectPool
public GenericObjectPool(org.apache.commons.pool.PoolableObjectFactory factory, int maxActive, byte whenExhaustedAction, long maxWait, boolean testOnBorrow, boolean testOnReturn)
- Create a new GenericObjectPool using the specified values.
GenericObjectPool
public GenericObjectPool(org.apache.commons.pool.PoolableObjectFactory factory, int maxActive, byte whenExhaustedAction, long maxWait, int maxIdle)
- Create a new GenericObjectPool using the specified values.
GenericObjectPool
public GenericObjectPool(org.apache.commons.pool.PoolableObjectFactory factory, int maxActive, byte whenExhaustedAction, long maxWait, int maxIdle, boolean testOnBorrow, boolean testOnReturn)
- Create a new GenericObjectPool using the specified values.
GenericObjectPool
public GenericObjectPool(org.apache.commons.pool.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.
GenericObjectPool
public GenericObjectPool(org.apache.commons.pool.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.
| Method Detail |
getMaxActive
public int getMaxActive()
- Returns the cap on the total number of active instances from my pool.
setMaxActive
public void setMaxActive(int maxActive)
- Sets the cap on the total number of active instances from my pool.
getWhenExhaustedAction
public byte getWhenExhaustedAction()
- Returns the action to take when the
borrowObject()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()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()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()55 method may block indefinitely.
setMaxWait
public void setMaxWait(long maxWait)
- Sets the maximum amount of time (in milliseconds) the
borrowObject()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()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.
setMinIdle
public void setMinIdle(int minIdle)
- 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)
getMinIdle
public 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)
getTestOnBorrow
public boolean getTestOnBorrow()
- When true, objects will be
validated 55
before being returned by the
borrowObject()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()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)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)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(GenericObjectPool.Config conf)
- Sets my configuration.
borrowObject
public java.lang.Object borrowObject() throws java.lang.Exception
- Description copied from interface:
org.apache.commons.pool.ObjectPool - Obtain an instance from my pool.
By contract, clients MUST return
the borrowed instance using
returnObject 55
or a related method as defined in an implementation
or sub-interface.
The behaviour of this method when the pool has been exhausted is not specified (although it may be specified by implementations).
- Specified by:
borrowObjectin interfaceorg.apache.commons.pool.ObjectPool
invalidateObject
public void invalidateObject(java.lang.Object obj) throws java.lang.Exception
- Description copied from interface:
org.apache.commons.pool.ObjectPool - 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.
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.ObjectPool
clear
public void clear()
- Description copied from interface:
org.apache.commons.pool.ObjectPool - Clears any objects sitting idle in the pool, releasing any
associated resources (optional operation).
- Specified by:
clearin interfaceorg.apache.commons.pool.ObjectPool
getNumActive
public int getNumActive()
- Description copied from interface:
org.apache.commons.pool.ObjectPool - Return the number of instances
currently borrowed from my pool
(optional operation).
- Specified by:
getNumActivein interfaceorg.apache.commons.pool.ObjectPool
getNumIdle
public int getNumIdle()
- Description copied from interface:
org.apache.commons.pool.ObjectPool - Return the number of instances
currently idle in my pool (optional operation).
This may be considered an approximation of the number
of objects that can be borrowed 55
without creating any new instances.
- Specified by:
getNumIdlein interfaceorg.apache.commons.pool.ObjectPool
returnObject
public void returnObject(java.lang.Object obj) throws java.lang.Exception
- Description copied from interface:
org.apache.commons.pool.ObjectPool - Return an instance to my pool.
By contract, obj MUST have been obtained
using borrowObject 55
or a related method as defined in an implementation
or sub-interface.
- Specified by:
returnObjectin interfaceorg.apache.commons.pool.ObjectPool
addObjectToPool
private void addObjectToPool(java.lang.Object obj, boolean decrementNumActive) throws java.lang.Exception
close
public void close()
throws java.lang.Exception
- Description copied from interface:
org.apache.commons.pool.ObjectPool - Close this pool, and free any resources associated with it.
- Specified by:
closein interfaceorg.apache.commons.pool.ObjectPool
setFactory
public void setFactory(org.apache.commons.pool.PoolableObjectFactory factory) throws java.lang.IllegalStateException
- Description copied from interface:
org.apache.commons.pool.ObjectPool - Sets the factory I use
to create new instances (optional operation).
- Specified by:
setFactoryin interfaceorg.apache.commons.pool.ObjectPool
evict
public void evict()
throws java.lang.Exception
ensureMinIdle
private void ensureMinIdle()
throws java.lang.Exception
- Check to see if we are below our minimum number of objects
if so enough to bring us back to our minimum.
calculateDeficit
private int calculateDeficit()
addObject
public void addObject()
throws java.lang.Exception
- Create an object, and place it into the pool.
addObject() is useful for "pre-loading" a pool with idle objects.
- Specified by:
addObjectin interfaceorg.apache.commons.pool.ObjectPool
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()
|
|||||||||
| 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