|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.apache.commons.pool.BaseKeyedObjectPool | +--org.apache.commons.pool.impl.GenericKeyedObjectPool
A configurable KeyedObjectPool
implementation.
When coupled with the appropriate KeyedPoolableObjectFactory
,
GenericKeyedObjectPool provides robust pooling functionality for
arbitrary objects.
A GenericKeyedObjectPool provides a number of configurable parameters:
maxActive
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
is exceeded, the pool is said to be exhausted.
maxIdle
controls the maximum number of objects that can
sit idle in the pool (per key) at any time. When non-positive, there
is no limit to the number of objects that may be idle at one time.
whenExhaustedAction
specifies the
behaviour of the borrowObject(java.lang.Object)
method when the pool is exhausted:
whenExhaustedAction
is
WHEN_EXHAUSTED_FAIL
, borrowObject(java.lang.Object)
will throw
a NoSuchElementException
whenExhaustedAction
is
WHEN_EXHAUSTED_GROW
, borrowObject(java.lang.Object)
will create a new
object and return it(essentially making maxActive
meaningless.)
whenExhaustedAction
is WHEN_EXHAUSTED_BLOCK
, borrowObject(java.lang.Object)
will block
(invoke Object.wait(long)
until a new or idle object is available.
If a positive maxWait
value is supplied, the borrowObject(java.lang.Object)
will block for at
most that many milliseconds, after which a NoSuchElementException
will be thrown. If maxWait
is non-positive,
the borrowObject(java.lang.Object)
method will block indefinitely.
testOnBorrow
is set, the pool will
attempt to validate each object before it is returned from the
borrowObject(java.lang.Object)
method. (Using the provided factory's
PoolableObjectFactory.validateObject(java.lang.Object)
method.) Objects that fail
to validate will be dropped from the pool, and a different object will
be borrowed.
testOnReturn
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)
method. (Using the provided factory's
PoolableObjectFactory.validateObject(java.lang.Object)
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
indicates how long the eviction thread should sleep before "runs" of examining
idle objects. When non-positive, no eviction thread will be launched.
minEvictableIdleTimeMillis
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
indicates whether or not idle
objects should be validated using the factory's
PoolableObjectFactory.validateObject(java.lang.Object)
method. Objects
that fail to validate will be dropped from the pool.
GenericObjectPool
Nested Class Summary | |
static class |
GenericKeyedObjectPool.Config
A simple "struct" encapsulating the configuration information for a GenericKeyedObjectPool . |
Field Summary | |
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 long |
DEFAULT_MAX_WAIT
The default maximum amount of time (in millis) the borrowObject(java.lang.Object) 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
The default value for getMinEvictableIdleTimeMillis() . |
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)
method should block until a new object is available, or the
maximum wait time 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)
method should fail, throwing a 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)
method should simply create a new object anyway. |
Constructor Summary | |
GenericKeyedObjectPool(KeyedPoolableObjectFactory factory)
Create a new GenericKeyedObjectPool using the specified values. |
|
GenericKeyedObjectPool(KeyedPoolableObjectFactory factory,
GenericKeyedObjectPool.Config config)
Create a new GenericKeyedObjectPool using the specified values. |
|
GenericKeyedObjectPool(KeyedPoolableObjectFactory factory,
int maxActive)
Create a new GenericKeyedObjectPool using the specified values. |
|
GenericKeyedObjectPool(KeyedPoolableObjectFactory factory,
int maxActive,
byte whenExhaustedAction,
long maxWait)
Create a new GenericKeyedObjectPool using the specified values. |
|
GenericKeyedObjectPool(KeyedPoolableObjectFactory factory,
int maxActive,
byte whenExhaustedAction,
long maxWait,
boolean testOnBorrow,
boolean testOnReturn)
Create a new GenericKeyedObjectPool using the specified values. |
|
GenericKeyedObjectPool(KeyedPoolableObjectFactory factory,
int maxActive,
byte whenExhaustedAction,
long maxWait,
int maxIdle)
Create a new GenericKeyedObjectPool using the specified values. |
|
GenericKeyedObjectPool(KeyedPoolableObjectFactory factory,
int maxActive,
byte whenExhaustedAction,
long maxWait,
int maxIdle,
boolean testOnBorrow,
boolean testOnReturn)
Create a new GenericKeyedObjectPool using the specified values. |
|
GenericKeyedObjectPool(KeyedPoolableObjectFactory factory,
int maxActive,
byte whenExhaustedAction,
long maxWait,
int maxIdle,
boolean testOnBorrow,
boolean testOnReturn,
long timeBetweenEvictionRunsMillis,
int numTestsPerEvictionRun,
long minEvictableIdleTimeMillis,
boolean testWhileIdle)
Create a new GenericKeyedObjectPool using the specified values. |
Method Summary | |
Object |
borrowObject(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(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. |
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(java.lang.Object) method should block before throwing
an exception when the pool is exhausted and the
"when exhausted" action is
WHEN_EXHAUSTED_BLOCK .
|
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(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(Object key)
Returns the number of instances corresponding to the given key currently idle in my pool (optional operation). |
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
before being returned by the borrowObject(java.lang.Object)
method. |
boolean |
getTestOnReturn()
When true, objects will be validated
before being returned to the pool within the
returnObject(java.lang.Object, java.lang.Object) . |
boolean |
getTestWhileIdle()
When true, objects will be validated
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) method
is invoked when the pool is exhausted (the maximum number
of "active" objects has been reached). |
void |
returnObject(Object key,
Object obj)
Return an instance to my pool. |
void |
setConfig(GenericKeyedObjectPool.Config conf)
Sets my configuration. |
void |
setFactory(KeyedPoolableObjectFactory 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(java.lang.Object) 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)
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
before being returned by the borrowObject(java.lang.Object)
method. |
void |
setTestOnReturn(boolean testOnReturn)
When true, objects will be validated
before being returned to the pool within the
returnObject(java.lang.Object, java.lang.Object) . |
void |
setTestWhileIdle(boolean testWhileIdle)
When true, objects will be validated
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) method
is invoked when the pool is exhausted (the maximum number
of "active" objects has been reached). |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int DEFAULT_MAX_ACTIVE
getMaxActive()
,
setMaxActive(int)
,
Constant Field Valuespublic static final int DEFAULT_MAX_IDLE
getMaxIdle()
,
setMaxIdle(int)
,
Constant Field Valuespublic static final long DEFAULT_MAX_WAIT
borrowObject(java.lang.Object)
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 long DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS
getMinEvictableIdleTimeMillis()
.
getMinEvictableIdleTimeMillis()
,
setMinEvictableIdleTimeMillis(long)
,
Constant Field Valuespublic static final int DEFAULT_NUM_TESTS_PER_EVICTION_RUN
getNumTestsPerEvictionRun()
,
setNumTestsPerEvictionRun(int)
,
getTimeBetweenEvictionRunsMillis()
,
setTimeBetweenEvictionRunsMillis(long)
,
Constant Field Valuespublic static final boolean DEFAULT_TEST_ON_BORROW
getTestOnBorrow()
,
setTestOnBorrow(boolean)
,
Constant Field Valuespublic static final boolean DEFAULT_TEST_ON_RETURN
getTestOnReturn()
,
setTestOnReturn(boolean)
,
Constant Field Valuespublic static final boolean DEFAULT_TEST_WHILE_IDLE
getTestWhileIdle()
,
setTestWhileIdle(boolean)
,
getTimeBetweenEvictionRunsMillis()
,
setTimeBetweenEvictionRunsMillis(long)
,
Constant Field Valuespublic static final long DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS
getTimeBetweenEvictionRunsMillis()
,
setTimeBetweenEvictionRunsMillis(long)
,
Constant Field Valuespublic static final byte DEFAULT_WHEN_EXHAUSTED_ACTION
WHEN_EXHAUSTED_BLOCK
,
WHEN_EXHAUSTED_FAIL
,
WHEN_EXHAUSTED_GROW
,
setWhenExhaustedAction(byte)
,
Constant Field Valuespublic static final byte WHEN_EXHAUSTED_BLOCK
borrowObject(java.lang.Object)
method should block until a new object is available, or the
maximum wait time
has been reached.
WHEN_EXHAUSTED_FAIL
,
WHEN_EXHAUSTED_GROW
,
setMaxWait(long)
,
getMaxWait()
,
setWhenExhaustedAction(byte)
,
Constant Field Valuespublic static final byte WHEN_EXHAUSTED_FAIL
borrowObject(java.lang.Object)
method should fail, throwing a NoSuchElementException
.
WHEN_EXHAUSTED_BLOCK
,
WHEN_EXHAUSTED_GROW
,
setWhenExhaustedAction(byte)
,
Constant Field Valuespublic static final byte WHEN_EXHAUSTED_GROW
borrowObject(java.lang.Object)
method should simply create a new object anyway.
WHEN_EXHAUSTED_FAIL
,
WHEN_EXHAUSTED_GROW
,
setWhenExhaustedAction(byte)
,
Constant Field ValuesConstructor Detail |
public GenericKeyedObjectPool(KeyedPoolableObjectFactory factory)
factory
- the (possibly null)KeyedPoolableObjectFactory to use to create, validate and destroy objectspublic GenericKeyedObjectPool(KeyedPoolableObjectFactory factory, GenericKeyedObjectPool.Config config)
factory
- the (possibly null)KeyedPoolableObjectFactory to use to create, validate and destroy objectsconfig
- a non-null GenericKeyedObjectPool.Config
describing my configurationpublic GenericKeyedObjectPool(KeyedPoolableObjectFactory factory, int maxActive)
factory
- the (possibly null)KeyedPoolableObjectFactory to use to create, validate and destroy objectsmaxActive
- the maximum number of objects that can be borrowed from me at one time (per key) (see setMaxActive(int)
)public GenericKeyedObjectPool(KeyedPoolableObjectFactory factory, int maxActive, byte whenExhaustedAction, long maxWait)
factory
- the (possibly null)KeyedPoolableObjectFactory to use to create, validate and destroy objectsmaxActive
- the maximum number of objects that can be borrowed from me at one time (per key) (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 an and whenExhaustedAction is WHEN_EXHAUSTED_BLOCK
(otherwise ignored) (see setMaxWait(long)
)public GenericKeyedObjectPool(KeyedPoolableObjectFactory factory, int maxActive, byte whenExhaustedAction, long maxWait, boolean testOnBorrow, boolean testOnReturn)
factory
- the (possibly null)KeyedPoolableObjectFactory to use to create, validate and destroy objectsmaxActive
- the maximum number of objects that can be borrowed from me at one time (per key) (see setMaxActive(int)
)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 setMaxWait(long)
)whenExhaustedAction
- the action to take when the pool is exhausted (see setWhenExhaustedAction(byte)
)testOnBorrow
- whether or not to validate objects before they are returned by the borrowObject(java.lang.Object)
method (see setTestOnBorrow(boolean)
)testOnReturn
- whether or not to validate objects after they are returned to the returnObject(java.lang.Object, java.lang.Object)
method (see setTestOnReturn(boolean)
)public GenericKeyedObjectPool(KeyedPoolableObjectFactory factory, int maxActive, byte whenExhaustedAction, long maxWait, int maxIdle)
factory
- the (possibly null)KeyedPoolableObjectFactory to use to create, validate and destroy objectsmaxActive
- the maximum number of objects that can be borrowed from me at one time (per key) (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 an and whenExhaustedAction is WHEN_EXHAUSTED_BLOCK
(otherwise ignored) (see setMaxWait(long)
)maxIdle
- the maximum number of idle objects in my pool (per key) (see setMaxIdle(int)
)public GenericKeyedObjectPool(KeyedPoolableObjectFactory factory, int maxActive, byte whenExhaustedAction, long maxWait, int maxIdle, boolean testOnBorrow, boolean testOnReturn)
factory
- the (possibly null)KeyedPoolableObjectFactory to use to create, validate and destroy objectsmaxActive
- the maximum number of objects that can be borrowed from me at one time (per key) (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 an and whenExhaustedAction is WHEN_EXHAUSTED_BLOCK
(otherwise ignored) (see getMaxWait()
)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(java.lang.Object)
method (see setTestOnBorrow(boolean)
)testOnReturn
- whether or not to validate objects after they are returned to the returnObject(java.lang.Object, java.lang.Object)
method (see setTestOnReturn(boolean)
)public GenericKeyedObjectPool(KeyedPoolableObjectFactory 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 from me at one time (per key) (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 an 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(java.lang.Object)
method (see setTestOnBorrow(boolean)
)testOnReturn
- whether or not to validate objects after they are returned to the returnObject(java.lang.Object, 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 eligable for evcition (see setMinEvictableIdleTimeMillis(long)
)testWhileIdle
- whether or not to validate objects in the idle object eviction thread, if any (see setTestWhileIdle(boolean)
)Method Detail |
public Object borrowObject(Object key) throws Exception
KeyedObjectPool
returnObject
,
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.
borrowObject
in interface KeyedObjectPool
borrowObject
in class BaseKeyedObjectPool
key
- the key used to obtain the object
Exception
public void clear()
KeyedObjectPool
UnsupportedOperationException
if the pool cannot be cleared.
clear
in interface KeyedObjectPool
clear
in class BaseKeyedObjectPool
public void clear(Object key)
KeyedObjectPool
UnsupportedOperationException
if the pool cannot be cleared.
clear
in interface KeyedObjectPool
clear
in class BaseKeyedObjectPool
key
- the key to clearpublic void close() throws Exception
KeyedObjectPool
close
in interface KeyedObjectPool
close
in class BaseKeyedObjectPool
Exception
public int getMaxActive()
setMaxActive(int)
public int getMaxIdle()
setMaxIdle(int)
public long getMaxWait()
borrowObject(java.lang.Object)
method should block before throwing
an exception when the pool is exhausted and the
"when exhausted" action
is
WHEN_EXHAUSTED_BLOCK
.
When less than 0, the borrowObject(java.lang.Object)
method
may block indefinitely.
setMaxWait(long)
,
setWhenExhaustedAction(byte)
,
WHEN_EXHAUSTED_BLOCK
public long getMinEvictableIdleTimeMillis()
setMinEvictableIdleTimeMillis(long)
,
setTimeBetweenEvictionRunsMillis(long)
public int getNumActive()
KeyedObjectPool
UnsupportedOperationException
if this information is not available.
getNumActive
in interface KeyedObjectPool
getNumActive
in class BaseKeyedObjectPool
public int getNumActive(Object key)
KeyedObjectPool
UnsupportedOperationException
if this information is not available.
getNumActive
in interface KeyedObjectPool
getNumActive
in class BaseKeyedObjectPool
key
- the key
public int getNumIdle()
KeyedObjectPool
UnsupportedOperationException
if this information is not available.
getNumIdle
in interface KeyedObjectPool
getNumIdle
in class BaseKeyedObjectPool
public int getNumIdle(Object key)
KeyedObjectPool
UnsupportedOperationException
if this information is not available.
getNumIdle
in interface KeyedObjectPool
getNumIdle
in class BaseKeyedObjectPool
key
- the key
public int getNumTestsPerEvictionRun()
setNumTestsPerEvictionRun(int)
,
setTimeBetweenEvictionRunsMillis(long)
public boolean getTestOnBorrow()
validated
before being returned by the borrowObject(java.lang.Object)
method. If the object fails to validate,
it will be dropped from the pool, and we will attempt
to borrow another.
setTestOnBorrow(boolean)
public boolean getTestOnReturn()
validated
before being returned to the pool within the
returnObject(java.lang.Object, java.lang.Object)
.
setTestOnReturn(boolean)
public boolean getTestWhileIdle()
validated
by the idle object evictor (if any). If an object
fails to validate, it will be dropped from the pool.
setTestWhileIdle(boolean)
,
setTimeBetweenEvictionRunsMillis(long)
public long getTimeBetweenEvictionRunsMillis()
setTimeBetweenEvictionRunsMillis(long)
public byte getWhenExhaustedAction()
borrowObject(java.lang.Object)
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_GROW
setWhenExhaustedAction(byte)
public void returnObject(Object key, Object obj) throws Exception
KeyedObjectPool
borrowObject
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.
returnObject
in interface KeyedObjectPool
returnObject
in class BaseKeyedObjectPool
key
- the key used to obtain the objectobj
- a borrowed
instance to be returned.
Exception
public void setConfig(GenericKeyedObjectPool.Config conf)
GenericKeyedObjectPool.Config
public void setFactory(KeyedPoolableObjectFactory factory) throws IllegalStateException
KeyedObjectPool
factory
I use
to create new instances (optional operation).
setFactory
in interface KeyedObjectPool
setFactory
in class BaseKeyedObjectPool
factory
- the KeyedPoolableObjectFactory
I use to create new instances.
IllegalStateException
- when the factory cannot be set at this timepublic void setMaxActive(int maxActive)
maxActive
- The cap on the total number of active instances from my pool.
Use a negative value for an infinite number of instances.getMaxActive()
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 setMaxWait(long maxWait)
borrowObject(java.lang.Object)
method should block before throwing
an exception when the pool is exhausted and the
"when exhausted" action
is
WHEN_EXHAUSTED_BLOCK
.
When less than 0, the borrowObject(java.lang.Object)
method
may block indefinitely.
getMaxWait()
,
setWhenExhaustedAction(byte)
,
WHEN_EXHAUSTED_BLOCK
public void setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis)
getMinEvictableIdleTimeMillis()
,
setTimeBetweenEvictionRunsMillis(long)
public void setNumTestsPerEvictionRun(int numTestsPerEvictionRun)
When a negative value is supplied, ceil(BaseKeyedObjectPool.numIdle(java.lang.Object)
)/abs(getNumTestsPerEvictionRun()
)
tests will be run. I.e., when the value is -n, roughly one nth of the
idle objects will be tested per run.
getNumTestsPerEvictionRun()
,
setTimeBetweenEvictionRunsMillis(long)
public void setTestOnBorrow(boolean testOnBorrow)
validated
before being returned by the borrowObject(java.lang.Object)
method. If the object fails to validate,
it will be dropped from the pool, and we will attempt
to borrow another.
getTestOnBorrow()
public void setTestOnReturn(boolean testOnReturn)
validated
before being returned to the pool within the
returnObject(java.lang.Object, java.lang.Object)
.
getTestOnReturn()
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.
getTestWhileIdle()
,
setTimeBetweenEvictionRunsMillis(long)
public void setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis)
getTimeBetweenEvictionRunsMillis()
public void setWhenExhaustedAction(byte whenExhaustedAction)
borrowObject(java.lang.Object)
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_GROW
getWhenExhaustedAction()
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |