Class GenericKeyedObjectPool<K,T>
- Type Parameters:
K
- The type of keys maintained by this pool.T
- Type of element pooled in this pool.
- All Implemented Interfaces:
Closeable
,AutoCloseable
,GenericKeyedObjectPoolMXBean<K>
,KeyedObjectPool<K,
T>
KeyedObjectPool
implementation.
When coupled with the appropriate KeyedPooledObjectFactory
,
GenericKeyedObjectPool
provides robust pooling functionality for
keyed objects. A GenericKeyedObjectPool
can be viewed as a map
of sub-pools, keyed on the (unique) key values provided to the
preparePool
, addObject
or
borrowObject
methods. Each time a new key value is
provided to one of these methods, a sub-new pool is created under the given
key to be managed by the containing GenericKeyedObjectPool.
Note that the current implementation uses a ConcurrentHashMap which uses equals() to compare keys. This means that distinct instance keys must be distinguishable using equals.
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 is maintained for each key. This is performed by an "idle object eviction" thread, which runs asynchronously. Caution should be used when configuring this optional feature. Eviction runs contend with client threads for access to objects in the pool, so if they run too frequently performance issues may result.
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.
This class is intended to be thread-safe.
- Since:
- 2.0
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate class
Maintains information on the per key queue for a given key.Nested classes/interfaces inherited from class org.datanucleus.store.rdbms.datasource.dbcp2.pool2.impl.BaseGenericObjectPool
BaseGenericObjectPool.EvictionIterator, BaseGenericObjectPool.Evictor, BaseGenericObjectPool.IdentityWrapper<T>
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate K
private final KeyedPooledObjectFactory
<K, T> private final boolean
private final ReadWriteLock
private int
private int
private int
private final AtomicInteger
private static final String
private final Map
<K, GenericKeyedObjectPool<K, T>.ObjectDeque<T>> Fields inherited from class org.datanucleus.store.rdbms.datasource.dbcp2.pool2.impl.BaseGenericObjectPool
closed, closeLock, createdCount, destroyedByBorrowValidationCount, destroyedByEvictorCount, destroyedCount, evictionIterator, evictionLock, MEAN_TIMING_STATS_CACHE_SIZE
-
Constructor Summary
ConstructorsConstructorDescriptionGenericKeyedObjectPool
(KeyedPooledObjectFactory<K, T> factory) Create a newGenericKeyedObjectPool
using defaults fromGenericKeyedObjectPoolConfig
.GenericKeyedObjectPool
(KeyedPooledObjectFactory<K, T> factory, GenericKeyedObjectPoolConfig<T> config) Create a newGenericKeyedObjectPool
using a specific configuration. -
Method Summary
Modifier and TypeMethodDescriptionprivate void
addIdleObject
(K key, PooledObject<T> p) Add an object to the set of idle objects for a given key.void
Create an object using thefactory
, passivate it, and then place it in the idle object pool.borrowObject
(K key) Equivalent to
.borrowObject
(key,BaseGenericObjectPool.getMaxWaitMillis()
)borrowObject
(K key, long borrowMaxWaitMillis) Borrows an object from the sub-pool associated with the given key using the specified waiting time which only applies ifBaseGenericObjectPool.getBlockWhenExhausted()
is true.private int
calculateDeficit
(GenericKeyedObjectPool<K, T>.ObjectDeque<T> objectDeque) Calculate the number of objects that need to be created to attempt to maintain the minimum number of idle objects while not exceeded the limits on the maximum number of objects either per key or totally.void
clear()
Clears any objects sitting idle in the pool by removing them from the idle instance sub-pools and then invoking the configured PoolableObjectFactory'sKeyedPooledObjectFactory.destroyObject(Object, PooledObject)
method on each idle instance.void
Clears the specified sub-pool, removing all pooled instances corresponding to the givenkey
.void
Clears oldest 15% of objects in pool.void
close()
Closes the keyed object pool.private PooledObject
<T> Create a new pooled object.private void
deregister
(K k) De-register the use of a key by an object.private boolean
destroy
(K key, PooledObject<T> toDestroy, boolean always) Destroy the wrapped, pooled object.(package private) void
Tries to ensure that the configured minimum number of idle instances are available in the pool.private void
ensureMinIdle
(K key) Ensure that the configured number of minimum idle objects is available in the pool for the given key.void
evict()
PerformnumTests
idle object eviction tests, evicting examined objects that meet the criteria for eviction.Obtain a reference to the factory used to create, destroy and validate the objects used by this pool.int
Returns the cap on the number of "idle" instances per key in the pool.int
Returns the limit on the number of object instances allocated by the pool (checked out or idle), per key.int
Returns the target for the minimum number of idle objects to maintain in each of the keyed sub-pools.int
Returns the total number of instances currently borrowed from this pool but not yet returned.int
getNumActive
(K key) Returns the number of instances currently borrowed from but not yet returned to the pool corresponding to the givenkey
.int
The number of instances currently idle in this pool.int
getNumIdle
(K key) Returns the number of instances corresponding to the givenkey
currently idle in this pool.private int
Calculate the number of objects to test in a run of the idle object evictor.int
Return an estimate of the number of threads currently blocked waiting for an object from the pool.Return an estimate of the number of threads currently blocked waiting for an object from the pool for each key.private boolean
Checks to see if there are any threads currently waiting to borrow objects but are blocked waiting for more objects to become available.void
invalidateObject
(K key, T obj) Invalidates an object from the pool.Provides information on all the objects in the pool, both idle (waiting to be borrowed) and active (currently borrowed).void
preparePool
(K key) Registers a key for pool control and ensures thatgetMinIdlePerKey()
idle instances are created.private GenericKeyedObjectPool<K,
T>.ObjectDeque <T> Register the use of a key by an object.void
returnObject
(K key, T obj) Returns an object to a keyed sub-pool.private void
Attempt to create one new instance to serve from the most heavily loaded pool that can add a new instance.void
Sets the configuration.void
setMaxIdlePerKey
(int maxIdlePerKey) Sets the cap on the number of "idle" instances per key in the pool.void
setMaxTotalPerKey
(int maxTotalPerKey) Sets the limit on the number of object instances allocated by the pool (checked out or idle), per key.void
setMinIdlePerKey
(int minIdlePerKey) Sets the target for the minimum number of idle objects to maintain in each of the keyed sub-pools.protected void
toStringAppendFields
(StringBuilder builder) Used by sub-classes to include the fields defined by the sub-class in theBaseObject.toString()
output.private void
whenWaitersAddObject
(K key, LinkedBlockingDeque<PooledObject<T>> idleObjects) Whether there is at least one thread waiting on this deque, add an pool object.Methods inherited from class org.datanucleus.store.rdbms.datasource.dbcp2.pool2.impl.BaseGenericObjectPool
assertOpen, getBlockWhenExhausted, getBorrowedCount, getCreatedCount, getCreationStackTrace, getDestroyedByBorrowValidationCount, getDestroyedByEvictorCount, getDestroyedCount, getEvictionPolicy, getEvictionPolicyClassName, getEvictorShutdownTimeoutMillis, getFairness, getJmxName, getLifo, getMaxBorrowWaitTimeMillis, getMaxTotal, getMaxWaitMillis, getMeanActiveTimeMillis, getMeanBorrowWaitTimeMillis, getMeanIdleTimeMillis, getMinEvictableIdleTimeMillis, getNumTestsPerEvictionRun, getReturnedCount, getSoftMinEvictableIdleTimeMillis, getSwallowedExceptionListener, getTestOnBorrow, getTestOnCreate, getTestOnReturn, getTestWhileIdle, getTimeBetweenEvictionRunsMillis, isClosed, jmxUnregister, markReturningState, setBlockWhenExhausted, setConfig, setEvictionPolicy, setEvictionPolicyClassName, setEvictionPolicyClassName, setEvictorShutdownTimeoutMillis, setLifo, setMaxTotal, setMaxWaitMillis, setMinEvictableIdleTimeMillis, setNumTestsPerEvictionRun, setSoftMinEvictableIdleTimeMillis, setSwallowedExceptionListener, setTestOnBorrow, setTestOnCreate, setTestOnReturn, setTestWhileIdle, setTimeBetweenEvictionRunsMillis, startEvictor, stopEvictor, swallowException, updateStatsBorrow, updateStatsReturn
Methods inherited from class org.datanucleus.store.rdbms.datasource.dbcp2.pool2.BaseObject
toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.datanucleus.store.rdbms.datasource.dbcp2.pool2.impl.GenericKeyedObjectPoolMXBean
getBlockWhenExhausted, getBorrowedCount, getCreatedCount, getCreationStackTrace, getDestroyedByBorrowValidationCount, getDestroyedByEvictorCount, getDestroyedCount, getFairness, getLifo, getMaxBorrowWaitTimeMillis, getMaxTotal, getMaxWaitMillis, getMeanActiveTimeMillis, getMeanBorrowWaitTimeMillis, getMeanIdleTimeMillis, getMinEvictableIdleTimeMillis, getNumTestsPerEvictionRun, getReturnedCount, getTestOnBorrow, getTestOnCreate, getTestOnReturn, getTestWhileIdle, getTimeBetweenEvictionRunsMillis, isClosed
Methods inherited from interface org.datanucleus.store.rdbms.datasource.dbcp2.pool2.KeyedObjectPool
addObjects, addObjects
-
Field Details
-
maxIdlePerKey
private volatile int maxIdlePerKey -
minIdlePerKey
private volatile int minIdlePerKey -
maxTotalPerKey
private volatile int maxTotalPerKey -
factory
-
fairness
private final boolean fairness -
poolMap
-
poolKeyList
-
keyLock
-
numTotal
-
evictionKeyIterator
-
evictionKey
-
ONAME_BASE
- See Also:
-
-
Constructor Details
-
GenericKeyedObjectPool
Create a newGenericKeyedObjectPool
using defaults fromGenericKeyedObjectPoolConfig
.- Parameters:
factory
- the factory to be used to create entries
-
GenericKeyedObjectPool
public GenericKeyedObjectPool(KeyedPooledObjectFactory<K, T> factory, GenericKeyedObjectPoolConfig<T> config) Create a newGenericKeyedObjectPool
using a specific configuration.- Parameters:
factory
- the factory to be used to create entriesconfig
- The configuration to use for this pool instance. The configuration is used by value. Subsequent changes to the configuration object will not be reflected in the pool.
-
-
Method Details
-
getMaxTotalPerKey
public int getMaxTotalPerKey()Returns the limit on the number of object instances allocated by the pool (checked out or idle), per key. When the limit is reached, the sub-pool is said to be exhausted. A negative value indicates no limit.- Specified by:
getMaxTotalPerKey
in interfaceGenericKeyedObjectPoolMXBean<K>
- Returns:
- the limit on the number of active instances per key
- See Also:
-
setMaxTotalPerKey
public void setMaxTotalPerKey(int maxTotalPerKey) Sets the limit on the number of object instances allocated by the pool (checked out or idle), per key. When the limit is reached, the sub-pool is said to be exhausted. A negative value indicates no limit.- Parameters:
maxTotalPerKey
- the limit on the number of active instances per key- See Also:
-
getMaxIdlePerKey
public int getMaxIdlePerKey()Returns the cap on the number of "idle" instances per key in the pool. If maxIdlePerKey is set too low on heavily loaded systems it is possible you will see objects being destroyed and almost immediately new objects being created. This is a result of the active threads momentarily returning objects faster than they are requesting them, causing the number of idle objects to rise above maxIdlePerKey. The best value for maxIdlePerKey for heavily loaded system will vary but the default is a good starting point.- Specified by:
getMaxIdlePerKey
in interfaceGenericKeyedObjectPoolMXBean<K>
- Returns:
- the maximum number of "idle" instances that can be held in a given keyed sub-pool or a negative value if there is no limit
- See Also:
-
setMaxIdlePerKey
public void setMaxIdlePerKey(int maxIdlePerKey) Sets the cap on the number of "idle" instances per key in the pool. If maxIdlePerKey is set too low on heavily loaded systems it is possible you will see objects being destroyed and almost immediately new objects being created. This is a result of the active threads momentarily returning objects faster than they are requesting them, causing the number of idle objects to rise above maxIdlePerKey. The best value for maxIdlePerKey for heavily loaded system will vary but the default is a good starting point.- Parameters:
maxIdlePerKey
- the maximum number of "idle" instances that can be held in a given keyed sub-pool. Use a negative value for no limit- See Also:
-
setMinIdlePerKey
public void setMinIdlePerKey(int minIdlePerKey) Sets the target for the minimum number of idle objects to maintain in each of the keyed sub-pools. This setting only has an effect if it is positive andBaseGenericObjectPool.getTimeBetweenEvictionRunsMillis()
is greater than zero. If this is the case, an attempt is made to ensure that each sub-pool has the required minimum number of instances during idle object eviction runs.If the configured value of minIdlePerKey is greater than the configured value for maxIdlePerKey then the value of maxIdlePerKey will be used instead.
- Parameters:
minIdlePerKey
- The minimum size of the each keyed pool- See Also:
-
getMinIdlePerKey
public int getMinIdlePerKey()Returns the target for the minimum number of idle objects to maintain in each of the keyed sub-pools. This setting only has an effect if it is positive andBaseGenericObjectPool.getTimeBetweenEvictionRunsMillis()
is greater than zero. If this is the case, an attempt is made to ensure that each sub-pool has the required minimum number of instances during idle object eviction runs.If the configured value of minIdlePerKey is greater than the configured value for maxIdlePerKey then the value of maxIdlePerKey will be used instead.
- Specified by:
getMinIdlePerKey
in interfaceGenericKeyedObjectPoolMXBean<K>
- Returns:
- minimum size of the each keyed pool
- See Also:
-
setConfig
Sets the configuration.- Parameters:
conf
- the new configuration to use. This is used by value.- See Also:
-
getFactory
Obtain a reference to the factory used to create, destroy and validate the objects used by this pool.- Returns:
- the factory
-
borrowObject
Equivalent to
.borrowObject
(key,BaseGenericObjectPool.getMaxWaitMillis()
)Obtains an instance from this pool for the specified
key
.Instances returned from this method will have been either newly created with
makeObject
or will be a previously idle object and have been activated withactivateObject
and then (optionally) validated withvalidateObject
.By contract, clients must return the borrowed object using
returnObject
,invalidateObject
, or a related method as defined in an implementation or sub-interface, using akey
that isequivalent
to the one used to borrow the instance in the first place.The behaviour of this method when the pool has been exhausted is not strictly specified (although it may be specified by implementations).
- Specified by:
borrowObject
in interfaceKeyedObjectPool<K,
T> - Parameters:
key
- the key used to obtain the object- Returns:
- an instance from this pool.
- Throws:
Exception
- whenmakeObject
throws an exception
-
borrowObject
Borrows an object from the sub-pool associated with the given key using the specified waiting time which only applies ifBaseGenericObjectPool.getBlockWhenExhausted()
is true.If there is one or more idle instances available in the sub-pool associated with the given key, then an idle instance will be selected based on the value of
BaseGenericObjectPool.getLifo()
, activated and returned. If activation fails, ortestOnBorrow
is set totrue
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 sub-pool associated with the given key, behavior depends on the
maxTotalPerKey
,maxTotal
, and (if applicable)BaseGenericObjectPool.getBlockWhenExhausted()
and the value passed in to theborrowMaxWaitMillis
parameter. If the number of instances checked out from the sub-pool under the given key is less thanmaxTotalPerKey
and the total number of instances in circulation (under all keys) is less thanmaxTotal
, a new instance is created, activated and (if applicable) validated and returned to the caller. If validation fails, aNoSuchElementException
will be thrown.If the associated sub-pool is exhausted (no available idle instances and no capacity to create new ones), this method will either block (
BaseGenericObjectPool.getBlockWhenExhausted()
is true) or throw aNoSuchElementException
(BaseGenericObjectPool.getBlockWhenExhausted()
is false). The length of time that this method will block whenBaseGenericObjectPool.getBlockWhenExhausted()
is true is determined by the value passed in to theborrowMaxWait
parameter.When
maxTotal
is set to a positive value and this method is invoked when at the limit with no idle instances available under the requested key, an attempt is made to create room by clearing the oldest 15% of the elements from the keyed sub-pools.When the pool is exhausted, multiple calling threads may be simultaneously blocked waiting for instances to become available. A "fairness" algorithm has been implemented to ensure that threads receive available instances in request arrival order.
- Parameters:
key
- pool keyborrowMaxWaitMillis
- The time to wait in milliseconds for an object to become available- Returns:
- object instance from the keyed pool
- Throws:
NoSuchElementException
- if a keyed object instance cannot be returned because the pool is exhausted.Exception
- if a keyed object instance cannot be returned due to an error
-
returnObject
Returns an object to a keyed sub-pool.If
maxIdle
is set to a positive value and the number of idle instances under the given key has reached this value, the returning instance is destroyed.If
testOnReturn
== true, the returning instance is validated before being returned to the idle instance sub-pool under the given key. In this case, if validation fails, the instance is destroyed.Exceptions encountered destroying objects for any reason are swallowed but notified via a
SwallowedExceptionListener
.- Specified by:
returnObject
in interfaceKeyedObjectPool<K,
T> - Parameters:
key
- pool keyobj
- instance to return to the keyed pool- Throws:
IllegalStateException
- if an object is returned to the pool that was not borrowed from it or if an object is returned to the pool multiple times
-
whenWaitersAddObject
Whether there is at least one thread waiting on this deque, add an pool object.- Parameters:
key
- pool key.idleObjects
- list of idle pool objects.
-
invalidateObject
Invalidates an object from the pool.By contract,
obj
must have been obtained usingborrowObject
or a related method as defined in an implementation or sub-interface using akey
that is equivalent to the one used to borrow theObject
in the first place.This method should be used when an object that has been borrowed is determined (due to an exception or other problem) to be invalid.
Activation of this method decrements the active count associated with the given keyed pool and attempts to destroy
obj.
- Specified by:
invalidateObject
in interfaceKeyedObjectPool<K,
T> - Parameters:
key
- pool keyobj
- instance to invalidate- Throws:
Exception
- if an exception occurs destroying the objectIllegalStateException
- if obj does not belong to the pool under the given key
-
clear
public void clear()Clears any objects sitting idle in the pool by removing them from the idle instance sub-pools and then invoking the configured PoolableObjectFactory'sKeyedPooledObjectFactory.destroyObject(Object, PooledObject)
method on each idle instance.Implementation notes:
- This method does not destroy or effect in any way instances that are checked out when it is invoked.
- Invoking this method does not prevent objects being returned to the idle instance pool, even during its execution. Additional instances may be returned while removed items are being destroyed.
- Exceptions encountered destroying idle instances are swallowed
but notified via a
SwallowedExceptionListener
.
- Specified by:
clear
in interfaceKeyedObjectPool<K,
T>
-
clear
Clears the specified sub-pool, removing all pooled instances corresponding to the givenkey
. Exceptions encountered destroying idle instances are swallowed but notified via aSwallowedExceptionListener
.- Specified by:
clear
in interfaceKeyedObjectPool<K,
T> - Parameters:
key
- the key to clear
-
getNumActive
public int getNumActive()Description copied from interface:KeyedObjectPool
Returns the total number of instances currently borrowed from this pool but not yet returned. Returns a negative value if this information is not available.- Specified by:
getNumActive
in interfaceGenericKeyedObjectPoolMXBean<K>
- Specified by:
getNumActive
in interfaceKeyedObjectPool<K,
T> - Returns:
- the total number of instances currently borrowed from this pool but not yet returned.
-
getNumIdle
public int getNumIdle()Description copied from class:BaseGenericObjectPool
The number of instances currently idle in this pool.- Specified by:
getNumIdle
in interfaceGenericKeyedObjectPoolMXBean<K>
- Specified by:
getNumIdle
in interfaceKeyedObjectPool<K,
T> - Specified by:
getNumIdle
in classBaseGenericObjectPool<T>
- Returns:
- count of instances available for checkout from the pool
-
getNumActive
Description copied from interface:KeyedObjectPool
Returns the number of instances currently borrowed from but not yet returned to the pool corresponding to the givenkey
. Returns a negative value if this information is not available.- Specified by:
getNumActive
in interfaceKeyedObjectPool<K,
T> - Parameters:
key
- the key to query- Returns:
- the number of instances currently borrowed from but not yet
returned to the pool corresponding to the given
key
.
-
getNumIdle
Description copied from interface:KeyedObjectPool
Returns the number of instances corresponding to the givenkey
currently idle in this pool. Returns a negative value if this information is not available.- Specified by:
getNumIdle
in interfaceKeyedObjectPool<K,
T> - Parameters:
key
- the key to query- Returns:
- the number of instances corresponding to the given
key
currently idle in this pool.
-
close
public void close()Closes the keyed object pool. Once the pool is closed,borrowObject(Object)
will fail with IllegalStateException, butreturnObject(Object, Object)
andinvalidateObject(Object, Object)
will continue to work, with returned objects destroyed on return.Destroys idle instances in the pool by invoking
clear()
.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceKeyedObjectPool<K,
T> - Specified by:
close
in classBaseGenericObjectPool<T>
-
clearOldest
public void clearOldest()Clears oldest 15% of objects in pool. The method sorts the objects into a TreeMap and then iterates the first 15% for removal. -
reuseCapacity
private void reuseCapacity()Attempt to create one new instance to serve from the most heavily loaded pool that can add a new instance. This method exists to ensure liveness in the pool when threads are parked waiting and capacity to create instances under the requested keys subsequently becomes available. This method is not guaranteed to create an instance and its selection of the most loaded pool that can create an instance may not always be correct, since it does not lock the pool and instances may be created, borrowed, returned or destroyed by other threads while it is executing. -
hasBorrowWaiters
private boolean hasBorrowWaiters()Checks to see if there are any threads currently waiting to borrow objects but are blocked waiting for more objects to become available.- Returns:
true
if there is at least one thread waiting otherwisefalse
-
evict
Perform
numTests
idle object eviction tests, evicting examined objects that meet the criteria for eviction. IftestWhileIdle
is true, examined objects are validated when visited (and removed if invalid); otherwise only objects that have been idle for more thanminEvicableIdleTimeMillis
are removed.Successive activations of this method examine objects in keyed sub-pools in sequence, cycling through the keys and examining objects in oldest-to-youngest order within the keyed sub-pools.
- Specified by:
evict
in classBaseGenericObjectPool<T>
- Throws:
Exception
- when there is a problem evicting idle objects.
-
create
Create a new pooled object.- Parameters:
key
- Key associated with new pooled object- Returns:
- The new, wrapped pooled object
- Throws:
Exception
- If the objection creation fails
-
destroy
Destroy the wrapped, pooled object.- Parameters:
key
- The key associated with the object to destroy.toDestroy
- The wrapped object to be destroyedalways
- Should the object be destroyed even if it is not currently in the set of idle objects for the given key- Returns:
true
if the object was destroyed, otherwisefalse
- Throws:
Exception
- If the object destruction failed
-
register
Register the use of a key by an object.register() and deregister() must always be used as a pair.
- Parameters:
k
- The key to register- Returns:
- The objects currently associated with the given key. If this method returns without throwing an exception then it will never return null.
-
deregister
De-register the use of a key by an object.register() and deregister() must always be used as a pair.
- Parameters:
k
- The key to de-register
-
ensureMinIdle
Description copied from class:BaseGenericObjectPool
Tries to ensure that the configured minimum number of idle instances are available in the pool.- Specified by:
ensureMinIdle
in classBaseGenericObjectPool<T>
- Throws:
Exception
- if an error occurs creating idle instances
-
ensureMinIdle
Ensure that the configured number of minimum idle objects is available in the pool for the given key.- Parameters:
key
- The key to check for idle objects- Throws:
Exception
- If a new object is required and cannot be created
-
addObject
Create an object using thefactory
, passivate it, and then place it in the idle object pool.addObject
is useful for "pre-loading" a pool with idle objects.- Specified by:
addObject
in interfaceKeyedObjectPool<K,
T> - Parameters:
key
- the key a new instance should be added to- Throws:
Exception
- whenKeyedPooledObjectFactory.makeObject(K)
fails.
-
addIdleObject
Add an object to the set of idle objects for a given key.- Parameters:
key
- The key to associate with the idle objectp
- The wrapped object to add.- Throws:
Exception
- If the associated factory fails to passivate the object
-
preparePool
Registers a key for pool control and ensures thatgetMinIdlePerKey()
idle instances are created.- Parameters:
key
- - The key to register for pool control.- Throws:
Exception
- If the associated factory throws an exception
-
getNumTests
private int getNumTests()Calculate the number of objects to test in a run of the idle object evictor.- Returns:
- The number of objects to test for validity
-
calculateDeficit
Calculate the number of objects that need to be created to attempt to maintain the minimum number of idle objects while not exceeded the limits on the maximum number of objects either per key or totally.- Parameters:
objectDeque
- The set of objects to check- Returns:
- The number of new objects to create
-
getNumActivePerKey
Description copied from interface:GenericKeyedObjectPoolMXBean
- Specified by:
getNumActivePerKey
in interfaceGenericKeyedObjectPoolMXBean<K>
- Returns:
- See
getNumActivePerKey()
-
getNumWaiters
public int getNumWaiters()Return an estimate of the number of threads currently blocked waiting for an object from the pool. This is intended for monitoring only, not for synchronization control.- Specified by:
getNumWaiters
in interfaceGenericKeyedObjectPoolMXBean<K>
- Returns:
- The estimate of the number of threads currently blocked waiting for an object from the pool
-
getNumWaitersByKey
Return an estimate of the number of threads currently blocked waiting for an object from the pool for each key. This is intended for monitoring only, not for synchronization control.- Specified by:
getNumWaitersByKey
in interfaceGenericKeyedObjectPoolMXBean<K>
- Returns:
- The estimate of the number of threads currently blocked waiting for an object from the pool for each key
-
listAllObjects
Provides information on all the objects in the pool, both idle (waiting to be borrowed) and active (currently borrowed).Note: This is named listAllObjects so it is presented as an operation via JMX. That means it won't be invoked unless the explicitly requested whereas all attributes will be automatically requested when viewing the attributes for an object in a tool like JConsole.
- Specified by:
listAllObjects
in interfaceGenericKeyedObjectPoolMXBean<K>
- Returns:
- Information grouped by key on all the objects in the pool
-
toStringAppendFields
Description copied from class:BaseObject
Used by sub-classes to include the fields defined by the sub-class in theBaseObject.toString()
output.- Overrides:
toStringAppendFields
in classBaseGenericObjectPool<T>
- Parameters:
builder
- Field names and values are appended to this object
-