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> - UsageTracking<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:
- 
Field SummaryFields inherited from class org.apache.tomcat.dbcp.pool2.impl.BaseGenericObjectPoolabandonedConfig, MEAN_TIMING_STATS_CACHE_SIZE
- 
Constructor SummaryConstructorsConstructorDescriptionGenericKeyedObjectPool(KeyedPooledObjectFactory<K, T> factory) Constructs a newGenericKeyedObjectPoolusing defaults fromGenericKeyedObjectPoolConfig.GenericKeyedObjectPool(KeyedPooledObjectFactory<K, T> factory, GenericKeyedObjectPoolConfig<T> config) Constructs a newGenericKeyedObjectPoolusing a specific configuration.GenericKeyedObjectPool(KeyedPooledObjectFactory<K, T> factory, GenericKeyedObjectPoolConfig<T> config, AbandonedConfig abandonedConfig) Creates a newGenericKeyedObjectPoolthat tracks and destroys objects that are checked out, but never returned to the pool.
- 
Method SummaryModifier and TypeMethodDescriptionvoidCreate an object using thefactory, passivate it, and then place it in the idle object pool.borrowObject(K key) Equivalent toborrowObject(key,BaseGenericObjectPool.getMaxWaitDuration())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.voidclear()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.voidClears the specified sub-pool, removing all pooled instances corresponding to the givenkey.voidClears the specified sub-pool, removing all pooled instances corresponding to the givenkey.voidClears oldest 15% of objects in pool.voidclose()Closes the keyed object pool.voidevict()PerformnumTestsidle object eviction tests, evicting examined objects that meet the criteria for eviction.Gets a reference to the factory used to create, destroy and validate the objects used by this pool.getKeys()Gets a copy of the pool key list.intGets the cap on the number of "idle" instances per key in the pool.intGets the limit on the number of object instances allocated by the pool (checked out or idle), per key.intGets the target for the minimum number of idle objects to maintain in each of the keyed sub-pools.intGets the total number of instances currently borrowed from this pool but not yet returned.intgetNumActive(K key) Gets the number of instances currently borrowed from but not yet returned to the pool corresponding to the givenkey.SeegetNumActivePerKey().intGets the number of instances currently idle in this pool.intgetNumIdle(K key) Gets the number of instances corresponding to the givenkeycurrently idle in this pool.intGets an estimate of the number of threads currently blocked waiting for an object from the pool.Gets an estimate of the number of threads currently blocked waiting for an object from the pool for each key.voidinvalidateObject(K key, T obj) Invalidates an object from the pool.voidinvalidateObject(K key, T obj, DestroyMode destroyMode) Invalidates an object from the pool, using the providedDestroyMode.Provides information on all the objects in the pool, both idle (waiting to be borrowed) and active (currently borrowed).voidpreparePool(K key) Registers a key for pool control and ensures thatgetMinIdlePerKey()idle instances are created.voidreturnObject(K key, T obj) Returns an object to a keyed sub-pool.voidSets the configuration.voidsetMaxIdlePerKey(int maxIdlePerKey) Sets the cap on the number of "idle" instances per key in the pool.voidsetMaxTotalPerKey(int maxTotalPerKey) Sets the limit on the number of object instances allocated by the pool (checked out or idle), per key.voidsetMinIdlePerKey(int minIdlePerKey) Sets the target for the minimum number of idle objects to maintain in each of the keyed sub-pools.protected voidtoStringAppendFields(StringBuilder builder) Used by sub-classes to include the fields defined by the sub-class in theBaseObject.toString()output.voidCalled every time a pooled object is used to enable the pool to better track borrowed objects.Methods inherited from class org.apache.tomcat.dbcp.pool2.impl.BaseGenericObjectPoolgetBlockWhenExhausted, getBorrowedCount, getCreatedCount, getCreationStackTrace, getDestroyedByBorrowValidationCount, getDestroyedByEvictorCount, getDestroyedCount, getDurationBetweenEvictionRuns, getEvictionPolicy, getEvictionPolicyClassName, getEvictorShutdownTimeout, getEvictorShutdownTimeoutDuration, getEvictorShutdownTimeoutMillis, getFairness, getJmxName, getLifo, getLogAbandoned, getMaxBorrowWaitDuration, getMaxBorrowWaitTimeMillis, getMaxTotal, getMaxWaitDuration, getMaxWaitMillis, getMeanActiveDuration, getMeanActiveTimeMillis, getMeanBorrowWaitDuration, getMeanBorrowWaitTimeMillis, getMeanIdleDuration, getMeanIdleTimeMillis, getMessageStatistics, getMinEvictableIdleDuration, getMinEvictableIdleTime, getMinEvictableIdleTimeMillis, getNumTestsPerEvictionRun, getRemoveAbandonedOnBorrow, getRemoveAbandonedOnMaintenance, getRemoveAbandonedTimeout, getRemoveAbandonedTimeoutDuration, getReturnedCount, getSoftMinEvictableIdleDuration, getSoftMinEvictableIdleTime, getSoftMinEvictableIdleTimeMillis, getSwallowedExceptionListener, getTestOnBorrow, getTestOnCreate, getTestOnReturn, getTestWhileIdle, getTimeBetweenEvictionRuns, getTimeBetweenEvictionRunsMillis, isAbandonedConfig, isClosed, markReturningState, setAbandonedConfig, setBlockWhenExhausted, setConfig, setDurationBetweenEvictionRuns, setEvictionPolicy, setEvictionPolicyClassName, setEvictionPolicyClassName, setEvictorShutdownTimeout, setEvictorShutdownTimeoutMillis, setLifo, setMaxTotal, setMaxWait, setMaxWaitMillis, setMessagesStatistics, setMinEvictableIdle, setMinEvictableIdleDuration, setMinEvictableIdleTime, setMinEvictableIdleTimeMillis, setNumTestsPerEvictionRun, setSoftMinEvictableIdle, setSoftMinEvictableIdleDuration, setSoftMinEvictableIdleTime, setSoftMinEvictableIdleTimeMillis, setSwallowedExceptionListener, setTestOnBorrow, setTestOnCreate, setTestOnReturn, setTestWhileIdle, setTimeBetweenEvictionRuns, setTimeBetweenEvictionRunsMillisMethods inherited from class org.apache.tomcat.dbcp.pool2.BaseObjecttoStringMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.tomcat.dbcp.pool2.impl.GenericKeyedObjectPoolMXBeangetBlockWhenExhausted, getBorrowedCount, getCreatedCount, getCreationStackTrace, getDestroyedByBorrowValidationCount, getDestroyedByEvictorCount, getDestroyedCount, getFairness, getLifo, getLogAbandoned, getMaxBorrowWaitTimeMillis, getMaxTotal, getMaxWaitMillis, getMeanActiveTimeMillis, getMeanBorrowWaitTimeMillis, getMeanIdleTimeMillis, getMinEvictableIdleTimeMillis, getNumTestsPerEvictionRun, getRemoveAbandonedOnBorrow, getRemoveAbandonedOnMaintenance, getRemoveAbandonedTimeout, getReturnedCount, getTestOnBorrow, getTestOnCreate, getTestOnReturn, getTestWhileIdle, getTimeBetweenEvictionRunsMillis, isAbandonedConfig, isClosedMethods inherited from interface org.apache.tomcat.dbcp.pool2.KeyedObjectPooladdObjects, addObjects
- 
Constructor Details- 
GenericKeyedObjectPoolConstructs a newGenericKeyedObjectPoolusing defaults fromGenericKeyedObjectPoolConfig.- Parameters:
- factory- the factory to be used to create entries
 
- 
GenericKeyedObjectPoolpublic GenericKeyedObjectPool(KeyedPooledObjectFactory<K, T> factory, GenericKeyedObjectPoolConfig<T> config) Constructs a newGenericKeyedObjectPoolusing a specific configuration.- Parameters:
- factory- the factory to be used to create entries
- config- 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.
 
- 
GenericKeyedObjectPoolpublic GenericKeyedObjectPool(KeyedPooledObjectFactory<K, T> factory, GenericKeyedObjectPoolConfig<T> config, AbandonedConfig abandonedConfig) Creates a newGenericKeyedObjectPoolthat tracks and destroys objects that are checked out, but never returned to the pool.- Parameters:
- factory- The object factory to be used to create object instances used by this pool
- config- The base pool 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.
- abandonedConfig- Configuration for abandoned object identification and removal. The configuration is used by value.
- Since:
- 2.10.0
 
 
- 
- 
Method Details- 
addObjectCreate an object using thefactory, passivate it, and then place it in the idle object pool.addObjectis useful for "pre-loading" a pool with idle objects.If there is no capacity available to add to the pool under the given key, this is a no-op (no exception, no impact to the pool). If the factory returns null when creating an instance, a NullPointerExceptionis thrown.- Specified by:
- addObjectin interface- KeyedObjectPool<K,- T> 
- Parameters:
- key- the key a new instance should be added to
- Throws:
- Exception- when- KeyedPooledObjectFactory.makeObject(K)fails.
 
- 
borrowObjectEquivalent toborrowObject(key,BaseGenericObjectPool.getMaxWaitDuration())key.Instances returned from this method will have been either newly created with makeObjector will be a previously idle object and have been activated withactivateObjectand 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 akeythat isequivalentto the one used to borrow the instance in the first place.The behavior of this method when the pool has been exhausted is not strictly specified (although it may be specified by implementations). - Specified by:
- borrowObjectin interface- KeyedObjectPool<K,- T> 
- Parameters:
- key- the key used to obtain the object
- Returns:
- an instance from this pool.
- Throws:
- IllegalStateException- after- closehas been called on this pool
- Exception- when- makeObjectthrows an exception
- NoSuchElementException- when the pool is exhausted and cannot or will not return another instance
 
- 
borrowObjectBorrows 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, ortestOnBorrowis set totrueand 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 theborrowMaxWaitMillisparameter. If the number of instances checked out from the sub-pool under the given key is less thanmaxTotalPerKeyand 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, aNoSuchElementExceptionwill be thrown. If the factory returns null when creating an instance, aNullPointerExceptionis 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 theborrowMaxWaitparameter.When maxTotalis 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 key
- borrowMaxWaitMillis- 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
 
- 
clearpublic 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:
- clearin interface- KeyedObjectPool<K,- T> 
 
- 
clearClears the specified sub-pool, removing all pooled instances corresponding to the givenkey. Exceptions encountered destroying idle instances are swallowed but notified via aSwallowedExceptionListener.If there are clients waiting to borrow objects, this method will attempt to reuse the capacity freed by this operation, adding instances to the most loaded keyed pools. To avoid triggering possible object creation, use clear(Object, boolean).- Specified by:
- clearin interface- KeyedObjectPool<K,- T> 
- Parameters:
- key- the key to clear
 
- 
clearClears the specified sub-pool, removing all pooled instances corresponding to the givenkey. Exceptions encountered destroying idle instances are swallowed but notified via aSwallowedExceptionListener.If reuseCapacity is true and there are clients waiting to borrow objects, this method will attempt to reuse the capacity freed by this operation, adding instances to the most loaded keyed pools. - Parameters:
- key- the key to clear
- reuseCapacity- whether or not to reuse freed capacity
- Since:
- 2.12.0
 
- 
clearOldestpublic 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.
- 
closepublic 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:
- closein interface- AutoCloseable
- Specified by:
- closein interface- Closeable
- Specified by:
- closein interface- KeyedObjectPool<K,- T> 
- Specified by:
- closein class- BaseGenericObjectPool<T>
 
- 
evictPerformnumTestsidle object eviction tests, evicting examined objects that meet the criteria for eviction. IftestWhileIdleis true, examined objects are validated when visited (and removed if invalid); otherwise only objects that have been idle for more thanminEvicableIdleTimeMillisare 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:
- evictin class- BaseGenericObjectPool<T>
- Throws:
- Exception- when there is a problem evicting idle objects.
 
- 
getFactoryGets a reference to the factory used to create, destroy and validate the objects used by this pool.- Returns:
- the factory
 
- 
getKeysGets a copy of the pool key list.- Specified by:
- getKeysin interface- KeyedObjectPool<K,- T> 
- Returns:
- a copy of the pool key list.
- Since:
- 2.12.0
 
- 
getMaxIdlePerKeypublic int getMaxIdlePerKey()Gets 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:
- getMaxIdlePerKeyin interface- GenericKeyedObjectPoolMXBean<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:
 
- 
getMaxTotalPerKeypublic int getMaxTotalPerKey()Gets 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:
- getMaxTotalPerKeyin interface- GenericKeyedObjectPoolMXBean<K>
- Returns:
- the limit on the number of active instances per key
- See Also:
 
- 
getMinIdlePerKeypublic int getMinIdlePerKey()Gets 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.getDurationBetweenEvictionRuns()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:
- getMinIdlePerKeyin interface- GenericKeyedObjectPoolMXBean<K>
- Returns:
- minimum size of the each keyed pool
- See Also:
 
- 
getNumActivepublic int getNumActive()Description copied from interface:KeyedObjectPoolGets 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:
- getNumActivein interface- GenericKeyedObjectPoolMXBean<K>
- Specified by:
- getNumActivein interface- KeyedObjectPool<K,- T> 
- Returns:
- the total number of instances currently borrowed from this pool but not yet returned.
 
- 
getNumActiveDescription copied from interface:KeyedObjectPoolGets 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:
- getNumActivein interface- KeyedObjectPool<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.
 
- 
getNumActivePerKeyDescription copied from interface:GenericKeyedObjectPoolMXBeanSeegetNumActivePerKey().- Specified by:
- getNumActivePerKeyin interface- GenericKeyedObjectPoolMXBean<K>
- Returns:
- See getNumActivePerKey().
 
- 
getNumIdlepublic int getNumIdle()Description copied from class:BaseGenericObjectPoolGets the number of instances currently idle in this pool.- Specified by:
- getNumIdlein interface- GenericKeyedObjectPoolMXBean<K>
- Specified by:
- getNumIdlein interface- KeyedObjectPool<K,- T> 
- Specified by:
- getNumIdlein class- BaseGenericObjectPool<T>
- Returns:
- count of instances available for checkout from the pool
 
- 
getNumIdleDescription copied from interface:KeyedObjectPoolGets the number of instances corresponding to the givenkeycurrently idle in this pool. Returns a negative value if this information is not available.- Specified by:
- getNumIdlein interface- KeyedObjectPool<K,- T> 
- Parameters:
- key- the key to query
- Returns:
- the number of instances corresponding to the given
 keycurrently idle in this pool.
 
- 
getNumWaiterspublic int getNumWaiters()Gets 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:
- getNumWaitersin interface- GenericKeyedObjectPoolMXBean<K>
- Returns:
- The estimate of the number of threads currently blocked waiting for an object from the pool
 
- 
getNumWaitersByKeyGets 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:
- getNumWaitersByKeyin interface- GenericKeyedObjectPoolMXBean<K>
- Returns:
- The estimate of the number of threads currently blocked waiting for an object from the pool for each key
 
- 
invalidateObjectInvalidates an object from the pool.By contract, objmust have been obtained usingborrowObjector a related method as defined in an implementation or sub-interface using akeythat is equivalent to the one used to borrow theObjectin 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:
- invalidateObjectin interface- KeyedObjectPool<K,- T> 
- Parameters:
- key- pool key
- obj- instance to invalidate
- Throws:
- Exception- if an exception occurs destroying the object
- IllegalStateException- if obj does not belong to the pool under the given key
 
- 
invalidateObjectInvalidates an object from the pool, using the providedDestroyMode.By contract, objmust have been obtained usingborrowObjector a related method as defined in an implementation or sub-interface using akeythat is equivalent to the one used to borrow theObjectin 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:
- invalidateObjectin interface- KeyedObjectPool<K,- T> 
- Parameters:
- key- pool key
- obj- instance to invalidate
- destroyMode- DestroyMode context provided to factory
- Throws:
- Exception- if an exception occurs destroying the object
- IllegalStateException- if obj does not belong to the pool under the given key
- Since:
- 2.9.0
 
- 
listAllObjectsProvides 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:
- listAllObjectsin interface- GenericKeyedObjectPoolMXBean<K>
- Returns:
- Information grouped by key on all the objects in the pool
 
- 
preparePoolRegisters 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
 
- 
returnObjectReturns an object to a keyed sub-pool.If maxIdleis 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:
- returnObjectin interface- KeyedObjectPool<K,- T> 
- Parameters:
- key- pool key
- obj- 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
 
- 
setConfigSets the configuration.- Parameters:
- conf- the new configuration to use. This is used by value.
- See Also:
 
- 
setMaxIdlePerKeypublic 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:
 
- 
setMaxTotalPerKeypublic 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:
 
- 
setMinIdlePerKeypublic 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.getDurationBetweenEvictionRuns()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:
 
- 
toStringAppendFieldsDescription copied from class:BaseObjectUsed by sub-classes to include the fields defined by the sub-class in theBaseObject.toString()output.- Overrides:
- toStringAppendFieldsin class- BaseGenericObjectPool<T>
- Parameters:
- builder- Field names and values are appended to this object
 
- 
useDescription copied from interface:UsageTrackingCalled every time a pooled object is used to enable the pool to better track borrowed objects.- Specified by:
- usein interface- UsageTracking<K>
- Parameters:
- pooledObject- The object that is being used.
- Since:
- 2.10.0
 
 
-