Handles JMX registration (if required) and the initialization required for monitoring.
The idle object evictor {@link TimerTask}.
Verifies that the pool is open. @throws IllegalStateException if the pool is closed.
Closes the pool, destroys the remaining idle objects and, if registered in JMX, deregisters it.
Tries to ensure that the configured minimum number of idle instances are available in the pool. @throws Exception if an error occurs creating idle instances
<p>Perform <code>numTests</code> idle object eviction tests, evicting examined objects that meet the criteria for eviction. If <code>testWhileIdle</code> is true, examined objects are validated when visited (and removed if invalid); otherwise only objects that have been idle for more than <code>minEvicableIdleTimeMillis</code> are removed.</p>
Returns whether to block when the <code>borrowObject()</code> method is invoked when the pool is exhausted (the maximum number of "active" objects has been reached).
The total number of objects successfully borrowed from this pool over the lifetime of the pool. @return the borrowed object count
The total number of objects created for this pool over the lifetime of the pool. @return the created object count
Provides the stack trace for the call that created this pool. JMX registration may trigger a memory leak so it is important that pools are deregistered when no longer used by calling the {@link #close()} method. This method is provided to assist with identifying code that creates but does not close it thereby creating a memory leak. @return pool creation stack trace
The total number of objects destroyed by this pool as a result of failing validation during <code>borrowObject()</code> over the lifetime of the pool. @return validation destroyed object count
The total number of objects destroyed by the evictor associated with this pool over the lifetime of the pool. @return the evictor destroyed object count
The total number of objects destroyed by this pool over the lifetime of the pool. @return the destroyed object count
Returns the {@link EvictionPolicy} defined for this pool.
Returns the name of the {@link EvictionPolicy} implementation that is used by this pool.
Gets the timeout that will be used when waiting for the Evictor to shutdown if this pool is closed and it is the only pool still using the the value for the Evictor.
Returns whether or not the pool serves threads waiting to borrow objects fairly. True means that waiting threads are served as if waiting in a FIFO queue.
Returns whether the pool has LIFO (last in, first out) behaviour with respect to idle objects - always returning the most recently used object from the pool, or as a FIFO (first in, first out) queue, where the pool always returns the oldest object in the idle object pool.
The maximum time a thread has waited to borrow objects from the pool. @return maximum wait time in milliseconds since the pool was created
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. When negative, there is no limit to the number of objects that can be managed by the pool at one time.
Returns the maximum amount of time (in milliseconds) the <code>borrowObject()</code> method should block before throwing an exception when the pool is exhausted and {@link #getBlockWhenExhausted} is true. When less than 0, the <code>borrowObject()</code> method may block indefinitely.
The mean time objects are active for based on the last {@link #MEAN_TIMING_STATS_CACHE_SIZE} objects returned to the pool. @return mean time an object has been checked out from the pool among recently returned objects
The mean time threads wait to borrow an object based on the last {@link #MEAN_TIMING_STATS_CACHE_SIZE} objects borrowed from the pool. @return mean time in milliseconds that a recently served thread has had to wait to borrow an object from the pool
The mean time objects are idle for based on the last {@link #MEAN_TIMING_STATS_CACHE_SIZE} objects borrowed from the pool. @return mean time an object has been idle in the pool among recently borrowed objects
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 - see {@link #setTimeBetweenEvictionRunsMillis(long)}). When non-positive, no objects will be evicted from the pool due to idle time alone.
The number of instances currently idle in this pool. @return count of instances available for checkout from the pool
Returns the maximum number of objects to examine during each run (if any) of the idle object evictor thread. When positive, the number of tests performed for a run will be the minimum of the configured value and the number of idle instances in the pool. When negative, the number of tests performed will be <code>ceil({@link #getNumIdle}/ abs({@link #getNumTestsPerEvictionRun}))</code> which means that when the value is <code>-n</code> roughly one nth of the idle objects will be tested per run.
The total number of objects returned to this pool over the lifetime of the pool. This excludes attempts to return the same object multiple times. @return the returned object count
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 - see {@link #setTimeBetweenEvictionRunsMillis(long)}), with the extra condition that at least <code>minIdle</code> object instances remain in the pool. This setting is overridden by {@link #getMinEvictableIdleTimeMillis} (that is, if {@link #getMinEvictableIdleTimeMillis} is positive, then {@link #getSoftMinEvictableIdleTimeMillis} is ignored).
The listener used (if any) to receive notifications of exceptions unavoidably swallowed by the pool.
Returns whether objects borrowed from the pool will be validated before being returned from the <code>borrowObject()</code> method. Validation is performed by the <code>validateObject()</code> method of the factory associated with the pool. If the object fails to validate, it will be removed from the pool and destroyed, and a new attempt will be made to borrow an object from the pool.
Returns whether objects created for the pool will be validated before being returned from the <code>borrowObject()</code> method. Validation is performed by the <code>validateObject()</code> method of the factory associated with the pool. If the object fails to validate, then <code>borrowObject()</code> will fail.
Returns whether objects borrowed from the pool will be validated when they are returned to the pool via the <code>returnObject()</code> method. Validation is performed by the <code>validateObject()</code> method of the factory associated with the pool. Returning objects that fail validation are destroyed rather then being returned the pool.
Returns whether objects sitting idle in the pool will be validated by the idle object evictor (if any - see {@link #setTimeBetweenEvictionRunsMillis(long)}). Validation is performed by the <code>validateObject()</code> method of the factory associated with the pool. If the object fails to validate, it will be removed from the pool and destroyed.
Returns the number of milliseconds to sleep between runs of the idle object evictor thread. When non-positive, no idle object evictor thread will be run.
Has this pool instance been closed. @return <code>true</code> when this pool has been closed.
Marks the object as returning to the pool. @param pooledObject instance to return to the keyed pool
Sets whether to block when the <code>borrowObject()</code> method is invoked when the pool is exhausted (the maximum number of "active" objects has been reached).
Sets the eviction policy for this pool.
Sets the timeout that will be used when waiting for the Evictor to shutdown if this pool is closed and it is the only pool still using the the value for the Evictor.
Sets whether the pool has LIFO (last in, first out) behaviour with respect to idle objects - always returning the most recently used object from the pool, or as a FIFO (first in, first out) queue, where the pool always returns the oldest object in the idle object pool.
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. Use a negative value for no limit.
Sets the maximum amount of time (in milliseconds) the <code>borrowObject()</code> method should block before throwing an exception when the pool is exhausted and {@link #getBlockWhenExhausted} is true. When less than 0, the <code>borrowObject()</code> method may block indefinitely.
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 - see {@link #setTimeBetweenEvictionRunsMillis(long)}). When non-positive, no objects will be evicted from the pool due to idle time alone.
Sets the maximum number of objects to examine during each run (if any) of the idle object evictor thread. When positive, the number of tests performed for a run will be the minimum of the configured value and the number of idle instances in the pool. When negative, the number of tests performed will be <code>ceil({@link #getNumIdle}/ abs({@link #getNumTestsPerEvictionRun}))</code> which means that when the value is <code>-n</code> roughly one nth of the idle objects will be tested per run.
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 - see {@link #setTimeBetweenEvictionRunsMillis(long)}), with the extra condition that at least <code>minIdle</code> object instances remain in the pool. This setting is overridden by {@link #getMinEvictableIdleTimeMillis} (that is, if {@link #getMinEvictableIdleTimeMillis} is positive, then {@link #getSoftMinEvictableIdleTimeMillis} is ignored).
The listener used (if any) to receive notifications of exceptions unavoidably swallowed by the pool.
Sets whether objects borrowed from the pool will be validated before being returned from the <code>borrowObject()</code> method. Validation is performed by the <code>validateObject()</code> method of the factory associated with the pool. If the object fails to validate, it will be removed from the pool and destroyed, and a new attempt will be made to borrow an object from the pool.
Sets whether objects created for the pool will be validated before being returned from the <code>borrowObject()</code> method. Validation is performed by the <code>validateObject()</code> method of the factory associated with the pool. If the object fails to validate, then <code>borrowObject()</code> will fail.
Sets whether objects borrowed from the pool will be validated when they are returned to the pool via the <code>returnObject()</code> method. Validation is performed by the <code>validateObject()</code> method of the factory associated with the pool. Returning objects that fail validation are destroyed rather then being returned the pool.
Returns whether objects sitting idle in the pool will be validated by the idle object evictor (if any - see {@link #setTimeBetweenEvictionRunsMillis(long)}). Validation is performed by the <code>validateObject()</code> method of the factory associated with the pool. If the object fails to validate, it will be removed from the pool and destroyed. Note that setting this property has no effect unless the idle object evictor is enabled by setting <code>timeBetweenEvictionRunsMillis</code> to a positive value.
Sets the number of milliseconds to sleep between runs of the idle object evictor thread. <ul> <li>When positive, the idle object evictor thread starts.</li> <li>When non-positive, no idle object evictor thread runs.</li> </ul>
<p>Starts the evictor with the given delay. If there is an evictor running when this method is called, it is stopped and replaced with a new evictor with the specified delay.</p>
Stops the evictor.
Swallows an exception and notifies the configured listener for swallowed exceptions queue.
Updates statistics after an object is borrowed from the pool. @param p object borrowed from the pool @param waitTime time (in milliseconds) that the borrowing thread had to wait
Updates statistics after an object is returned to the pool. @param activeTime the amount of time (in milliseconds) that the returning object was checked out
The size of the caches used to store historical data for some attributes so that rolling means may be calculated.
Used by sub-classes to include the fields defined by the sub-class in the {@link #toString()} output.
Base class that provides common functionality for {@link GenericObjectPool} and {@link GenericKeyedObjectPool}. The primary reason this class exists is reduce code duplication between the two pool implementations.
@param <T> Type of element pooled in this pool.
This class is intended to be thread-safe.