@Deprecated
public class PatchedGenericObjectPool
extends BaseObjectPool
Hybris note: This is a patched version of GenericObjectPool taken from 1.5.4 which we had to create
due to https://issues.apache.org/jira/browse/POOL-179.
Apart from the code marked with // TODO hybris nothing has been changed.
ObjectPool implementation.
When coupled with the appropriate PoolableObjectFactory, GenericObjectPool provides robust pooling
functionality for arbitrary objects.
A GenericObjectPool provides a number of configurable parameters:
maxActive controls the maximum number of objects that can be allocated by the pool
(checked out to clients, or idle awaiting checkout) at a given time. When non-positive, there is no limit to the
number of objects that can be managed by the pool at one time. When maxActive is
reached, the pool is said to be exhausted. The default setting for this parameter is 8.maxIdle 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. The default setting for this
parameter is 8.whenExhaustedAction specifies the behavior of the borrowObject() method
when the pool is exhausted:
whenExhaustedAction is WHEN_EXHAUSTED_FAIL,
borrowObject() will throw a NoSuchElementExceptionwhenExhaustedAction is WHEN_EXHAUSTED_GROW,
borrowObject() will create a new object and return it (essentially making maxActive meaningless.)whenExhaustedAction is WHEN_EXHAUSTED_BLOCK,
borrowObject() will block (invoke Object.wait()) until a new or idle object is available. If a
positive maxWait value is supplied, then borrowObject() will block for at most that
many milliseconds, after which a NoSuchElementException will be thrown. If maxWait
is non-positive, the borrowObject() method will block indefinitely.whenExhaustedAction setting is WHEN_EXHAUSTED_BLOCK and the default
maxWait setting is -1. By default, therefore, borrowObject will block indefinitely until an
idle instance becomes available.testOnBorrow is set, the pool will attempt to validate each object before it is
returned from the borrowObject() method. (Using the provided factory's
PoolableObjectFactory#validateObject method.) Objects that fail to validate will be dropped from the pool,
and a different object will be borrowed. The default setting for this parameter is false.testOnReturn is set, the pool will attempt to validate each object before it is
returned to the pool in the returnObject(java.lang.Object) method. (Using the provided factory's
PoolableObjectFactory#validateObject method.) Objects that fail to validate will be dropped from the pool.
The default setting for this parameter is false.Optionally, one may configure the pool to examine and possibly evict objects as they sit idle in the pool and to ensure that a minimum number of idle objects are available. This is performed by an "idle object eviction" thread, which runs asynchronously. Caution should be used when configuring this optional feature. Eviction runs require an exclusive synchronization lock on the pool, so if they run too frequently and / or incur excessive latency when creating, destroying or validating object instances, performance issues may result. The idle object eviction thread may be configured using the following attributes:
timeBetweenEvictionRunsMillis indicates how long the eviction thread
should sleep before "runs" of examining idle objects. When non-positive, no eviction thread will be launched. The
default setting for this parameter is -1 (i.e., idle object eviction is disabled by default).minEvictableIdleTimeMillis specifies the minimum amount of time that an
object may sit idle in the pool before it is eligible for eviction due to idle time. When non-positive, no object
will be dropped from the pool due to idle time alone. This setting has no effect unless
timeBetweenEvictionRunsMillis > 0. The default setting for this parameter is 30 minutes.testWhileIdle indicates whether or not idle objects should be validated using the
factory's PoolableObjectFactory#validateObject method. Objects that fail to validate will be dropped from the
pool. This setting has no effect unless timeBetweenEvictionRunsMillis > 0. The default setting for this
parameter is false.softMinEvictableIdleTimeMillis specifies the minimum amount of time
an object may sit idle in the pool before it is eligible for eviction by the idle object evictor (if any), with the
extra condition that at least "minIdle" object instances remain in the pool. When non-positive, no objects will be
evicted from the pool due to idle time alone. This setting has no effect unless
timeBetweenEvictionRunsMillis > 0. and it is superceded by minEvictableIdleTimeMillis (that is, if minEvictableIdleTimeMillis is positive, then
softMinEvictableIdleTimeMillis is ignored). The default setting for this parameter is -1 (disabled).numTestsPerEvictionRun determines the number of objects examined in each
run of the idle object evictor. This setting has no effect unless timeBetweenEvictionRunsMillis > 0. The
default setting for this parameter is 3.
The pool can be configured to behave as a LIFO queue with respect to idle objects - always returning the most recently used object from the pool, or as a FIFO queue, where borrowObject always returns the oldest object in the idle object pool.
lifo determines whether or not the pool returns idle objects in last-in-first-out order. The
default setting for this parameter is true.
GenericObjectPool is not usable without a PoolableObjectFactory. A non-null factory must be
provided either as a constructor argument or via a call to setFactory(PoolableObjectFactory) before the pool is used.
Implementation note: To prevent possible deadlocks, care has been taken to ensure that no call to a factory method will occur within a synchronization block. See POOL-125 and DBCP-44 for more information.
GenericKeyedObjectPool| Modifier and Type | Field and Description |
|---|---|
static boolean |
DEFAULT_LIFO
Deprecated.
The default LIFO status.
|
static int |
DEFAULT_MAX_ACTIVE
Deprecated.
The default cap on the total number of active instances from the pool.
|
static int |
DEFAULT_MAX_IDLE
Deprecated.
The default cap on the number of "sleeping" instances in the pool.
|
static long |
DEFAULT_MAX_WAIT
Deprecated.
The default maximum amount of time (in milliseconds) the
borrowObject() method should block before throwing
an exception when the pool is exhausted and the "when exhausted" action is
WHEN_EXHAUSTED_BLOCK. |
static long |
DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS
Deprecated.
The default value for
getMinEvictableIdleTimeMillis(). |
static int |
DEFAULT_MIN_IDLE
Deprecated.
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
Deprecated.
The default number of objects to examine per run in the idle object evictor.
|
static long |
DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS
Deprecated.
The default value for
getSoftMinEvictableIdleTimeMillis(). |
static boolean |
DEFAULT_TEST_ON_BORROW
Deprecated.
The default "test on borrow" value.
|
static boolean |
DEFAULT_TEST_ON_RETURN
Deprecated.
The default "test on return" value.
|
static boolean |
DEFAULT_TEST_WHILE_IDLE
Deprecated.
The default "test while idle" value.
|
static long |
DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS
Deprecated.
The default "time between eviction runs" value.
|
static byte |
DEFAULT_WHEN_EXHAUSTED_ACTION
Deprecated.
The default "when exhausted action" for the pool.
|
static byte |
WHEN_EXHAUSTED_BLOCK
Deprecated.
A "when exhausted action" type indicating that when the pool is exhausted (i.e., the maximum number of active
objects has been reached), the
borrowObject() method should block until a new object is available, or the
maximum wait time has been reached. |
static byte |
WHEN_EXHAUSTED_FAIL
Deprecated.
A "when exhausted action" type indicating that when the pool is exhausted (i.e., the maximum number of active
objects has been reached), the
borrowObject() method should fail, throwing a NoSuchElementException
. |
static byte |
WHEN_EXHAUSTED_GROW
Deprecated.
A "when exhausted action" type indicating that when the pool is exhausted (i.e., the maximum number of active
objects has been reached), the
borrowObject() method should simply create a new object anyway. |
| Constructor and Description |
|---|
PatchedGenericObjectPool()
Deprecated.
Create a new GenericObjectPool with default properties.
|
PatchedGenericObjectPool(PoolableObjectFactory factory)
Deprecated.
Create a new GenericObjectPool using the specified factory.
|
PatchedGenericObjectPool(PoolableObjectFactory factory,
GenericObjectPool.Config config)
Deprecated.
Create a new GenericObjectPool using the specified values.
|
PatchedGenericObjectPool(PoolableObjectFactory factory,
int maxActive)
Deprecated.
Create a new GenericObjectPool using the specified values.
|
PatchedGenericObjectPool(PoolableObjectFactory factory,
int maxActive,
byte whenExhaustedAction,
long maxWait)
Deprecated.
Create a new GenericObjectPool using the specified values.
|
PatchedGenericObjectPool(PoolableObjectFactory factory,
int maxActive,
byte whenExhaustedAction,
long maxWait,
boolean testOnBorrow,
boolean testOnReturn)
Deprecated.
Create a new GenericObjectPool using the specified values.
|
PatchedGenericObjectPool(PoolableObjectFactory factory,
int maxActive,
byte whenExhaustedAction,
long maxWait,
int maxIdle)
Deprecated.
Create a new GenericObjectPool using the specified values.
|
PatchedGenericObjectPool(PoolableObjectFactory factory,
int maxActive,
byte whenExhaustedAction,
long maxWait,
int maxIdle,
boolean testOnBorrow,
boolean testOnReturn)
Deprecated.
Create a new GenericObjectPool using the specified values.
|
PatchedGenericObjectPool(PoolableObjectFactory factory,
int maxActive,
byte whenExhaustedAction,
long maxWait,
int maxIdle,
boolean testOnBorrow,
boolean testOnReturn,
long timeBetweenEvictionRunsMillis,
int numTestsPerEvictionRun,
long minEvictableIdleTimeMillis,
boolean testWhileIdle)
Deprecated.
Create a new GenericObjectPool using the specified values.
|
PatchedGenericObjectPool(PoolableObjectFactory factory,
int maxActive,
byte whenExhaustedAction,
long maxWait,
int maxIdle,
int minIdle,
boolean testOnBorrow,
boolean testOnReturn,
long timeBetweenEvictionRunsMillis,
int numTestsPerEvictionRun,
long minEvictableIdleTimeMillis,
boolean testWhileIdle)
Deprecated.
Create a new GenericObjectPool using the specified values.
|
PatchedGenericObjectPool(PoolableObjectFactory factory,
int maxActive,
byte whenExhaustedAction,
long maxWait,
int maxIdle,
int minIdle,
boolean testOnBorrow,
boolean testOnReturn,
long timeBetweenEvictionRunsMillis,
int numTestsPerEvictionRun,
long minEvictableIdleTimeMillis,
boolean testWhileIdle,
long softMinEvictableIdleTimeMillis)
Deprecated.
Create a new GenericObjectPool using the specified values.
|
PatchedGenericObjectPool(PoolableObjectFactory factory,
int maxActive,
byte whenExhaustedAction,
long maxWait,
int maxIdle,
int minIdle,
boolean testOnBorrow,
boolean testOnReturn,
long timeBetweenEvictionRunsMillis,
int numTestsPerEvictionRun,
long minEvictableIdleTimeMillis,
boolean testWhileIdle,
long softMinEvictableIdleTimeMillis,
boolean lifo)
Deprecated.
Create a new GenericObjectPool using the specified values.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addObject()
Deprecated.
Create an object, and place it into the pool.
|
java.lang.Object |
borrowObject()
Deprecated.
Borrows an object from the pool.
|
void |
clear()
Deprecated.
Clears any objects sitting idle in the pool by removing them from the idle instance pool and then invoking the
configured
PoolableObjectFactory#destroyObject(Object) method on each idle instance. |
void |
close()
Deprecated.
Closes the pool.
|
void |
evict()
Deprecated.
Perform
numTests idle object eviction tests, evicting examined objects that meet the criteria for
eviction. |
boolean |
getLifo()
Deprecated.
Whether or not the idle object pool acts as a LIFO queue.
|
int |
getMaxActive()
Deprecated.
Returns the maximum number of objects that can be allocated by the pool (checked out to clients, or idle awaiting
checkout) at a given time.
|
int |
getMaxIdle()
Deprecated.
Returns the cap on the number of "idle" instances in the pool.
|
long |
getMaxWait()
Deprecated.
Returns the maximum amount of time (in milliseconds) the
borrowObject() method should block before throwing
an exception when the pool is exhausted and the "when exhausted" action is
WHEN_EXHAUSTED_BLOCK. |
long |
getMinEvictableIdleTimeMillis()
Deprecated.
Returns the minimum amount of time an object may sit idle in the pool before it is eligible for eviction by the
idle object evictor (if any).
|
int |
getMinIdle()
Deprecated.
Returns the minimum number of objects allowed in the pool before the evictor thread (if active) spawns new
objects.
|
int |
getNumActive()
Deprecated.
Return the number of instances currently borrowed from this pool.
|
int |
getNumIdle()
Deprecated.
Return the number of instances currently idle in this pool.
|
int |
getNumTestsPerEvictionRun()
Deprecated.
Returns the max number of objects to examine during each run of the idle object evictor thread (if any).
|
long |
getSoftMinEvictableIdleTimeMillis()
Deprecated.
Returns the minimum amount of time an object may sit idle in the pool before it is eligible for eviction by the
idle object evictor (if any), with the extra condition that at least "minIdle" amount of object remain in the
pool.
|
boolean |
getTestOnBorrow()
Deprecated.
When true, objects will be
validated before being returned
by the borrowObject() method. |
boolean |
getTestOnReturn()
Deprecated.
When true, objects will be
validated before being returned
to the pool within the returnObject(java.lang.Object). |
boolean |
getTestWhileIdle()
Deprecated.
When true, objects will be
validated by the idle object
evictor (if any). |
long |
getTimeBetweenEvictionRunsMillis()
Deprecated.
Returns the number of milliseconds to sleep between runs of the idle object evictor thread.
|
byte |
getWhenExhaustedAction()
Deprecated.
Returns the action to take when the
borrowObject() method is invoked when the pool is exhausted (the
maximum number of "active" objects has been reached). |
void |
invalidateObject(java.lang.Object obj)
Deprecated.
Invalidates the given object instance.
|
void |
returnObject(java.lang.Object obj)
Deprecated.
Returns an object instance to the pool.
|
void |
setConfig(GenericObjectPool.Config conf)
Deprecated.
Sets my configuration.
|
void |
setFactory(PoolableObjectFactory factory)
Deprecated.
Sets the
factory this pool uses to create new instances. |
void |
setLifo(boolean lifo)
Deprecated.
Sets the LIFO property of the pool.
|
void |
setMaxActive(int maxActive)
Deprecated.
Sets the cap on the number of objects that can be allocated by the pool (checked out to clients, or idle awaiting
checkout) at a given time.
|
void |
setMaxIdle(int maxIdle)
Deprecated.
Sets the cap on the number of "idle" instances in the pool.
|
void |
setMaxWait(long maxWait)
Deprecated.
Sets the maximum amount of time (in milliseconds) the
borrowObject() method should block before throwing an
exception when the pool is exhausted and the "when exhausted" action is
WHEN_EXHAUSTED_BLOCK. |
void |
setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis)
Deprecated.
Sets the minimum amount of time an object may sit idle in the pool before it is eligible for eviction by the idle
object evictor (if any).
|
void |
setMinIdle(int minIdle)
Deprecated.
Sets the minimum number of objects allowed in the pool before the evictor thread (if active) spawns new objects.
|
void |
setNumTestsPerEvictionRun(int numTestsPerEvictionRun)
Deprecated.
Sets the max number of objects to examine during each run of the idle object evictor thread (if any).
|
void |
setSoftMinEvictableIdleTimeMillis(long softMinEvictableIdleTimeMillis)
Deprecated.
Sets the minimum amount of time an object may sit idle in the pool before it is eligible for eviction by the idle
object evictor (if any), with the extra condition that at least "minIdle" object instances remain in the pool.
|
void |
setTestOnBorrow(boolean testOnBorrow)
Deprecated.
When true, objects will be
validated before being returned
by the borrowObject() method. |
void |
setTestOnReturn(boolean testOnReturn)
Deprecated.
When true, objects will be
validated before being returned
to the pool within the returnObject(java.lang.Object). |
void |
setTestWhileIdle(boolean testWhileIdle)
Deprecated.
When true, objects will be
validated by the idle object
evictor (if any). |
void |
setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis)
Deprecated.
Sets the number of milliseconds to sleep between runs of the idle object evictor thread.
|
void |
setWhenExhaustedAction(byte whenExhaustedAction)
Deprecated.
Sets the action to take when the
borrowObject() method is invoked when the pool is exhausted (the maximum
number of "active" objects has been reached). |
protected void |
startEvictor(long delay)
Deprecated.
Start the eviction thread or service, or when delay is non-positive, stop it if it is already running.
|
public static final byte WHEN_EXHAUSTED_FAIL
borrowObject() method should fail, throwing a NoSuchElementException
.public static final byte WHEN_EXHAUSTED_BLOCK
borrowObject() method should block until a new object is available, or the
maximum wait time has been reached.public static final byte WHEN_EXHAUSTED_GROW
borrowObject() method should simply create a new object anyway.public static final int DEFAULT_MAX_IDLE
getMaxIdle(),
setMaxIdle(int),
Constant Field Valuespublic static final int DEFAULT_MIN_IDLE
getMinIdle(),
setMinIdle(int),
Constant Field Valuespublic static final int DEFAULT_MAX_ACTIVE
getMaxActive(),
Constant Field Valuespublic static final byte DEFAULT_WHEN_EXHAUSTED_ACTION
public static final boolean DEFAULT_LIFO
setLifo(boolean),
Constant Field Valuespublic static final long DEFAULT_MAX_WAIT
borrowObject() method should block before throwing
an exception when the pool is exhausted and the "when exhausted" action is
WHEN_EXHAUSTED_BLOCK.getMaxWait(),
setMaxWait(long),
Constant Field Valuespublic static final boolean DEFAULT_TEST_ON_BORROW
public static final boolean DEFAULT_TEST_ON_RETURN
public static final boolean DEFAULT_TEST_WHILE_IDLE
public static final long DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS
public static final int DEFAULT_NUM_TESTS_PER_EVICTION_RUN
public static final long DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS
getMinEvictableIdleTimeMillis().public static final long DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS
getSoftMinEvictableIdleTimeMillis().public PatchedGenericObjectPool()
public PatchedGenericObjectPool(PoolableObjectFactory factory)
factory - the (possibly null)PoolableObjectFactory to use to create, validate and destroy objectspublic PatchedGenericObjectPool(PoolableObjectFactory factory,
GenericObjectPool.Config config)
factory - the (possibly null)PoolableObjectFactory to use to create, validate and destroy objectsconfig - a non-null GenericObjectPool.Config describing my configurationpublic PatchedGenericObjectPool(PoolableObjectFactory factory,
int maxActive)
factory - the (possibly null)PoolableObjectFactory to use to create, validate and destroy objectsmaxActive - the maximum number of objects that can be borrowed from me at one time (see setMaxActive(int))public PatchedGenericObjectPool(PoolableObjectFactory factory,
int maxActive,
byte whenExhaustedAction,
long maxWait)
factory - the (possibly null)PoolableObjectFactory to use to create, validate and destroy objectsmaxActive - the maximum number of objects that can be borrowed from me at one time (see setMaxActive(int))whenExhaustedAction - the action to take when the pool is exhausted (see getWhenExhaustedAction())maxWait - the maximum amount of time to wait for an idle object when the pool is exhausted an and
whenExhaustedAction is WHEN_EXHAUSTED_BLOCK (otherwise ignored) (see getMaxWait()
)public PatchedGenericObjectPool(PoolableObjectFactory factory,
int maxActive,
byte whenExhaustedAction,
long maxWait,
boolean testOnBorrow,
boolean testOnReturn)
factory - the (possibly null)PoolableObjectFactory to use to create, validate and destroy objectsmaxActive - the maximum number of objects that can be borrowed at one time (see setMaxActive(int))whenExhaustedAction - the action to take when the pool is exhausted (see getWhenExhaustedAction())maxWait - the maximum amount of time to wait for an idle object when the pool is exhausted an and
whenExhaustedAction is WHEN_EXHAUSTED_BLOCK (otherwise ignored) (see getMaxWait()
)testOnBorrow - whether or not to validate objects before they are returned by the borrowObject() method (see
getTestOnBorrow())testOnReturn - whether or not to validate objects after they are returned to the returnObject(java.lang.Object) method (see
getTestOnReturn())public PatchedGenericObjectPool(PoolableObjectFactory factory,
int maxActive,
byte whenExhaustedAction,
long maxWait,
int maxIdle)
factory - the (possibly null)PoolableObjectFactory to use to create, validate and destroy objectsmaxActive - the maximum number of objects that can be borrowed at one time (see setMaxActive(int))whenExhaustedAction - the action to take when the pool is exhausted (see getWhenExhaustedAction())maxWait - the maximum amount of time to wait for an idle object when the pool is exhausted and
whenExhaustedAction is WHEN_EXHAUSTED_BLOCK (otherwise ignored) (see getMaxWait()
)maxIdle - the maximum number of idle objects in my pool (see getMaxIdle())public PatchedGenericObjectPool(PoolableObjectFactory factory,
int maxActive,
byte whenExhaustedAction,
long maxWait,
int maxIdle,
boolean testOnBorrow,
boolean testOnReturn)
factory - the (possibly null)PoolableObjectFactory to use to create, validate and destroy objectsmaxActive - the maximum number of objects that can be borrowed at one time (see setMaxActive(int))whenExhaustedAction - the action to take when the pool is exhausted (see getWhenExhaustedAction())maxWait - the maximum amount of time to wait for an idle object when the pool is exhausted and
whenExhaustedAction is WHEN_EXHAUSTED_BLOCK (otherwise ignored) (see getMaxWait()
)maxIdle - the maximum number of idle objects in my pool (see getMaxIdle())testOnBorrow - whether or not to validate objects before they are returned by the borrowObject() method (see
getTestOnBorrow())testOnReturn - whether or not to validate objects after they are returned to the returnObject(java.lang.Object) method (see
getTestOnReturn())public PatchedGenericObjectPool(PoolableObjectFactory factory,
int maxActive,
byte whenExhaustedAction,
long maxWait,
int maxIdle,
boolean testOnBorrow,
boolean testOnReturn,
long timeBetweenEvictionRunsMillis,
int numTestsPerEvictionRun,
long minEvictableIdleTimeMillis,
boolean testWhileIdle)
factory - the (possibly null)PoolableObjectFactory to use to create, validate and destroy objectsmaxActive - the maximum number of objects that can be borrowed at one time (see setMaxActive(int))whenExhaustedAction - the action to take when the pool is exhausted (see setWhenExhaustedAction(byte))maxWait - the maximum amount of time to wait for an idle object when the pool is exhausted and
whenExhaustedAction is WHEN_EXHAUSTED_BLOCK (otherwise ignored) (see setMaxWait(long)
)maxIdle - the maximum number of idle objects in my pool (see setMaxIdle(int))testOnBorrow - whether or not to validate objects before they are returned by the borrowObject() method (see
setTestOnBorrow(boolean))testOnReturn - whether or not to validate objects after they are returned to the returnObject(java.lang.Object) method (see
setTestOnReturn(boolean))timeBetweenEvictionRunsMillis - the amount of time (in milliseconds) to sleep between examining idle objects for eviction (see
setTimeBetweenEvictionRunsMillis(long))numTestsPerEvictionRun - the number of idle objects to examine per run within the idle object eviction thread (if any) (see
setNumTestsPerEvictionRun(int))minEvictableIdleTimeMillis - the minimum number of milliseconds an object can sit idle in the pool before it is eligible for eviction
(see setMinEvictableIdleTimeMillis(long))testWhileIdle - whether or not to validate objects in the idle object eviction thread, if any (see
setTestWhileIdle(boolean))public PatchedGenericObjectPool(PoolableObjectFactory factory,
int maxActive,
byte whenExhaustedAction,
long maxWait,
int maxIdle,
int minIdle,
boolean testOnBorrow,
boolean testOnReturn,
long timeBetweenEvictionRunsMillis,
int numTestsPerEvictionRun,
long minEvictableIdleTimeMillis,
boolean testWhileIdle)
factory - the (possibly null)PoolableObjectFactory to use to create, validate and destroy objectsmaxActive - the maximum number of objects that can be borrowed at one time (see setMaxActive(int))whenExhaustedAction - the action to take when the pool is exhausted (see setWhenExhaustedAction(byte))maxWait - the maximum amount of time to wait for an idle object when the pool is exhausted and
whenExhaustedAction is WHEN_EXHAUSTED_BLOCK (otherwise ignored) (see setMaxWait(long)
)maxIdle - the maximum number of idle objects in my pool (see setMaxIdle(int))minIdle - the minimum number of idle objects in my pool (see setMinIdle(int))testOnBorrow - whether or not to validate objects before they are returned by the borrowObject() method (see
setTestOnBorrow(boolean))testOnReturn - whether or not to validate objects after they are returned to the returnObject(java.lang.Object) method (see
setTestOnReturn(boolean))timeBetweenEvictionRunsMillis - the amount of time (in milliseconds) to sleep between examining idle objects for eviction (see
setTimeBetweenEvictionRunsMillis(long))numTestsPerEvictionRun - the number of idle objects to examine per run within the idle object eviction thread (if any) (see
setNumTestsPerEvictionRun(int))minEvictableIdleTimeMillis - the minimum number of milliseconds an object can sit idle in the pool before it is eligible for eviction
(see setMinEvictableIdleTimeMillis(long))testWhileIdle - whether or not to validate objects in the idle object eviction thread, if any (see
setTestWhileIdle(boolean))public PatchedGenericObjectPool(PoolableObjectFactory factory,
int maxActive,
byte whenExhaustedAction,
long maxWait,
int maxIdle,
int minIdle,
boolean testOnBorrow,
boolean testOnReturn,
long timeBetweenEvictionRunsMillis,
int numTestsPerEvictionRun,
long minEvictableIdleTimeMillis,
boolean testWhileIdle,
long softMinEvictableIdleTimeMillis)
factory - the (possibly null)PoolableObjectFactory to use to create, validate and destroy objectsmaxActive - the maximum number of objects that can be borrowed at one time (see setMaxActive(int))whenExhaustedAction - the action to take when the pool is exhausted (see setWhenExhaustedAction(byte))maxWait - the maximum amount of time to wait for an idle object when the pool is exhausted and
whenExhaustedAction is WHEN_EXHAUSTED_BLOCK (otherwise ignored) (see setMaxWait(long)
)maxIdle - the maximum number of idle objects in my pool (see setMaxIdle(int))minIdle - the minimum number of idle objects in my pool (see setMinIdle(int))testOnBorrow - whether or not to validate objects before they are returned by the borrowObject() method (see
setTestOnBorrow(boolean))testOnReturn - whether or not to validate objects after they are returned to the returnObject(java.lang.Object) method (see
setTestOnReturn(boolean))timeBetweenEvictionRunsMillis - the amount of time (in milliseconds) to sleep between examining idle objects for eviction (see
setTimeBetweenEvictionRunsMillis(long))numTestsPerEvictionRun - the number of idle objects to examine per run within the idle object eviction thread (if any) (see
setNumTestsPerEvictionRun(int))minEvictableIdleTimeMillis - the minimum number of milliseconds an object can sit idle in the pool before it is eligible for eviction
(see setMinEvictableIdleTimeMillis(long))testWhileIdle - whether or not to validate objects in the idle object eviction thread, if any (see
setTestWhileIdle(boolean))softMinEvictableIdleTimeMillis - the minimum number of milliseconds an object can sit idle in the pool before it is eligible for eviction
with the extra condition that at least "minIdle" amount of object remain in the pool. (see
setSoftMinEvictableIdleTimeMillis(long))public PatchedGenericObjectPool(PoolableObjectFactory factory,
int maxActive,
byte whenExhaustedAction,
long maxWait,
int maxIdle,
int minIdle,
boolean testOnBorrow,
boolean testOnReturn,
long timeBetweenEvictionRunsMillis,
int numTestsPerEvictionRun,
long minEvictableIdleTimeMillis,
boolean testWhileIdle,
long softMinEvictableIdleTimeMillis,
boolean lifo)
factory - the (possibly null)PoolableObjectFactory to use to create, validate and destroy objectsmaxActive - the maximum number of objects that can be borrowed at one time (see setMaxActive(int))whenExhaustedAction - the action to take when the pool is exhausted (see setWhenExhaustedAction(byte))maxWait - the maximum amount of time to wait for an idle object when the pool is exhausted and
whenExhaustedAction is WHEN_EXHAUSTED_BLOCK (otherwise ignored) (see setMaxWait(long)
)maxIdle - the maximum number of idle objects in my pool (see setMaxIdle(int))minIdle - the minimum number of idle objects in my pool (see setMinIdle(int))testOnBorrow - whether or not to validate objects before they are returned by the borrowObject() method (see
setTestOnBorrow(boolean))testOnReturn - whether or not to validate objects after they are returned to the returnObject(java.lang.Object) method (see
setTestOnReturn(boolean))timeBetweenEvictionRunsMillis - the amount of time (in milliseconds) to sleep between examining idle objects for eviction (see
setTimeBetweenEvictionRunsMillis(long))numTestsPerEvictionRun - the number of idle objects to examine per run within the idle object eviction thread (if any) (see
setNumTestsPerEvictionRun(int))minEvictableIdleTimeMillis - the minimum number of milliseconds an object can sit idle in the pool before it is eligible for eviction
(see setMinEvictableIdleTimeMillis(long))testWhileIdle - whether or not to validate objects in the idle object eviction thread, if any (see
setTestWhileIdle(boolean))softMinEvictableIdleTimeMillis - the minimum number of milliseconds an object can sit idle in the pool before it is eligible for eviction
with the extra condition that at least "minIdle" amount of object remain in the pool. (see
setSoftMinEvictableIdleTimeMillis(long))lifo - whether or not objects are returned in last-in-first-out order from the idle object pool (see
setLifo(boolean))public int getMaxActive()
setMaxActive(int)public void setMaxActive(int maxActive)
maxActive - The cap on the total number of object instances managed by the pool. Negative values mean that there is
no limit to the number of objects allocated by the pool.getMaxActive()public byte getWhenExhaustedAction()
borrowObject() method is invoked when the pool is exhausted (the
maximum number of "active" objects has been reached).WHEN_EXHAUSTED_BLOCK, WHEN_EXHAUSTED_FAIL or WHEN_EXHAUSTED_GROWsetWhenExhaustedAction(byte)public void setWhenExhaustedAction(byte whenExhaustedAction)
borrowObject() method is invoked when the pool is exhausted (the maximum
number of "active" objects has been reached).whenExhaustedAction - the action code, which must be one of WHEN_EXHAUSTED_BLOCK, WHEN_EXHAUSTED_FAIL, or
WHEN_EXHAUSTED_GROWgetWhenExhaustedAction()public long getMaxWait()
borrowObject() method should block before throwing
an exception when the pool is exhausted and the "when exhausted" action is
WHEN_EXHAUSTED_BLOCK.
When less than or equal to 0, the borrowObject() method may block indefinitely.setMaxWait(long),
setWhenExhaustedAction(byte),
WHEN_EXHAUSTED_BLOCKpublic void setMaxWait(long maxWait)
borrowObject() method should block before throwing an
exception when the pool is exhausted and the "when exhausted" action is
WHEN_EXHAUSTED_BLOCK.
When less than or equal to 0, the borrowObject() method may block indefinitely.maxWait - maximum number of milliseconds to block when borrowing an object.getMaxWait(),
setWhenExhaustedAction(byte),
WHEN_EXHAUSTED_BLOCKpublic int getMaxIdle()
setMaxIdle(int)public void setMaxIdle(int maxIdle)
maxIdle - The cap on the number of "idle" instances in the pool. Use a negative value to indicate an unlimited
number of idle instances.getMaxIdle()public void setMinIdle(int minIdle)
numActive + numIdle >= maxActive. This setting has no effect if
the idle object evictor is disabled (i.e. if timeBetweenEvictionRunsMillis <= 0).minIdle - The minimum number of objects.getMinIdle(),
getTimeBetweenEvictionRunsMillis()public int getMinIdle()
setMinIdle(int)public boolean getTestOnBorrow()
validated before being returned
by the borrowObject() method. If the object fails to validate, it will be dropped from the pool, and we
will attempt to borrow another.true if objects are validated before being borrowed.setTestOnBorrow(boolean)public void setTestOnBorrow(boolean testOnBorrow)
validated before being returned
by the borrowObject() method. If the object fails to validate, it will be dropped from the pool, and we
will attempt to borrow another.testOnBorrow - true if objects should be validated before being borrowed.getTestOnBorrow()public boolean getTestOnReturn()
validated before being returned
to the pool within the returnObject(java.lang.Object).true when objects will be validated after returned to returnObject(java.lang.Object).setTestOnReturn(boolean)public void setTestOnReturn(boolean testOnReturn)
validated before being returned
to the pool within the returnObject(java.lang.Object).testOnReturn - true so objects will be validated after returned to returnObject(java.lang.Object).getTestOnReturn()public long getTimeBetweenEvictionRunsMillis()
setTimeBetweenEvictionRunsMillis(long)public void setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis)
timeBetweenEvictionRunsMillis - number of milliseconds to sleep between evictor runs.getTimeBetweenEvictionRunsMillis()public int getNumTestsPerEvictionRun()
setNumTestsPerEvictionRun(int),
setTimeBetweenEvictionRunsMillis(long)public void setNumTestsPerEvictionRun(int numTestsPerEvictionRun)
When a negative value is supplied, ceil(getNumIdle())/abs(getNumTestsPerEvictionRun())
tests will be run. That is, when the value is -n, roughly one nth of the idle objects will be tested
per run. When the value is positive, the number of tests actually performed in each run will be the minimum of
this value and the number of instances idle in the pool.
numTestsPerEvictionRun - max number of objects to examine during each evictor run.getNumTestsPerEvictionRun(),
setTimeBetweenEvictionRunsMillis(long)public long getMinEvictableIdleTimeMillis()
setMinEvictableIdleTimeMillis(long),
setTimeBetweenEvictionRunsMillis(long)public void setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis)
minEvictableIdleTimeMillis - minimum amount of time an object may sit idle in the pool before it is eligible for eviction.getMinEvictableIdleTimeMillis(),
setTimeBetweenEvictionRunsMillis(long)public long getSoftMinEvictableIdleTimeMillis()
setSoftMinEvictableIdleTimeMillis(long)public void setSoftMinEvictableIdleTimeMillis(long softMinEvictableIdleTimeMillis)
softMinEvictableIdleTimeMillis - minimum amount of time an object may sit idle in the pool before it is eligible for eviction.getSoftMinEvictableIdleTimeMillis()public boolean getTestWhileIdle()
validated by the idle object
evictor (if any). If an object fails to validate, it will be dropped from the pool.true when objects will be validated by the evictor.setTestWhileIdle(boolean),
setTimeBetweenEvictionRunsMillis(long)public void setTestWhileIdle(boolean testWhileIdle)
validated by the idle object
evictor (if any). If an object fails to validate, it will be dropped from the pool.testWhileIdle - true so objects will be validated by the evictor.getTestWhileIdle(),
setTimeBetweenEvictionRunsMillis(long)public boolean getLifo()
true if the pool is configured to act as a LIFO queuepublic void setLifo(boolean lifo)
lifo - the new value for the LIFO propertypublic void setConfig(GenericObjectPool.Config conf)
conf - configuration to use.GenericObjectPool.Configpublic java.lang.Object borrowObject()
throws java.lang.Exception
Borrows an object from the pool.
If there is an idle instance available in the pool, then either the most-recently returned (if lifo == true) or "oldest" (lifo == false) instance sitting idle in the pool will be activated and returned. If
activation fails, or testOnBorrow is set to true and validation fails, the instance is
destroyed and the next available instance is examined. This continues until either a valid instance is returned or
there are no more idle instances available.
If there are no idle instances available in the pool, behavior depends on the maxActive
and (if applicable) whenExhaustedAction and maxWait
properties. If the number of instances checked out from the pool is less than maxActive, a new
instance is created, activated and (if applicable) validated and returned to the caller.
If the pool is exhausted (no available idle instances and no capacity to create new ones), this method will either
block (WHEN_EXHAUSTED_BLOCK), throw a NoSuchElementException (WHEN_EXHAUSTED_FAIL),
or grow (WHEN_EXHAUSTED_GROW - ignoring maxActive). The length of time that this method will block when
whenExhaustedAction == WHEN_EXHAUSTED_BLOCK is determined by the maxWait
property.
When the pool is exhausted, multiple calling threads may be simultaneously blocked waiting for instances to become available. As of pool 1.5, a "fairness" algorithm has been implemented to ensure that threads receive available instances in request arrival order.
java.util.NoSuchElementException - if an instance cannot be returnedjava.lang.Exceptionpublic void invalidateObject(java.lang.Object obj)
throws java.lang.Exception
Invalidates the given object instance. Decrements the active count and destroys the instance.
obj - instance to invalidatejava.lang.Exception - if an exception occurs destroying the objectpublic void clear()
PoolableObjectFactory#destroyObject(Object) method on each idle instance.
Implementation notes:
public int getNumActive()
public int getNumIdle()
public void returnObject(java.lang.Object obj)
throws java.lang.Exception
Returns an object instance to the pool.
If maxIdle is set to a positive value and the number of idle instances has reached this
value, the returning instance is destroyed.
If testOnReturn == true, the returning instance is validated before being returned to
the idle instance pool. In this case, if validation fails, the instance is destroyed.
Note: There is no guard to prevent an object being returned to the pool multiple times. Clients are expected to discard references to returned objects and ensure that an object is not returned to the pool multiple times in sequence (i.e., without being borrowed again between returns). Violating this contract will result in the same object appearing multiple times in the pool and pool counters (numActive, numIdle) returning incorrect values.
obj - instance to return to the pooljava.lang.Exceptionpublic void close()
throws java.lang.Exception
borrowObject() will fail with IllegalStateException, but
returnObject(Object) and invalidateObject(Object) will continue to work. This method does not
clear() the pool. The method is idempotent - that is, it is OK to call it on a closed pool.java.lang.Exceptionpublic void setFactory(PoolableObjectFactory factory)
throws java.lang.IllegalStateException
factory this pool uses to create new instances. Trying to change the
factory while there are borrowed objects will throw an IllegalStateException.factory - the PoolableObjectFactory used to create new instances.java.lang.IllegalStateException - when the factory cannot be set at this timepublic void evict()
throws java.lang.Exception
Perform numTests idle object eviction tests, evicting examined objects that meet the criteria for
eviction. If testWhileIdle is true, examined objects are validated when visited (and removed if
invalid); otherwise only objects that have been idle for more than minEvicableIdletimeMillis are
removed.
Successive activations of this method examine objects in in sequence, cycling through objects in oldest-to-youngest order.
java.lang.Exception - if the pool is closed or eviction fails.public void addObject()
throws java.lang.Exception
java.lang.Exceptionprotected void startEvictor(long delay)
delay - milliseconds between evictor runs.Copyright © 2018 SAP SE. All Rights Reserved.