Creates a new <code>GenericObjectPool</code> using defaults from {@link GenericObjectPoolConfig}.
Creates a new <code>GenericObjectPool</code> using a specific configuration.
Creates a new <code>GenericObjectPool</code> that tracks and destroys objects that are checked out, but never returned to the pool.
Creates an object, and place it into the pool. addObject() is useful for "pre-loading" a pool with idle objects. <p> If there is no capacity available to add to the pool, this is a no-op (no exception, no impact to the pool). </p>
Equivalent to <code>{@link #borrowObject(long) borrowObject}({@link #getMaxWaitMillis()})</code>. <p> {@inheritDoc} </p>
Borrows an object from the pool using the specific waiting time which only applies if {@link #getBlockWhenExhausted()} is true. <p> If there is one or more idle instance available in the pool, then an idle instance will be selected based on the value of {@link #getLifo()}, activated and returned. If activation fails, or {@link #getTestOnBorrow() testOnBorrow} is set to <code>true</code> 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. </p> <p> If there are no idle instances available in the pool, behavior depends on the {@link #getMaxTotal() maxTotal}, (if applicable) {@link #getBlockWhenExhausted()} and the value passed in to the <code>borrowMaxWaitMillis</code> parameter. If the number of instances checked out from the pool is less than <code>maxTotal,</code> a new instance is created, activated and (if applicable) validated and returned to the caller. If validation fails, a <code>NoSuchElementException</code> is thrown. </p> <p> If the pool is exhausted (no available idle instances and no capacity to create new ones), this method will either block (if {@link #getBlockWhenExhausted()} is true) or throw a <code>NoSuchElementException</code> (if {@link #getBlockWhenExhausted()} is false). The length of time that this method will block when {@link #getBlockWhenExhausted()} is true is determined by the value passed in to the <code>borrowMaxWaitMillis</code> parameter. </p> <p> 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. </p>
Clears any objects sitting idle in the pool by removing them from the idle instance pool and then invoking the configured {@link PooledObjectFactory#destroyObject(PooledObject)} method on each idle instance. <p> Implementation notes: </p> <ul> <li>This method does not destroy or effect in any way instances that are checked out of the pool when it is invoked.</li> <li>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.</li> <li>Exceptions encountered destroying idle instances are swallowed but notified via a {@link SwallowedExceptionListener}.</li> </ul>
Closes the pool. Once the pool is closed, {@link #borrowObject()} will fail with IllegalStateException, but {@link #returnObject(Object)} and {@link #invalidateObject(Object)} will continue to work, with returned objects destroyed on return. <p> Destroys idle instances in the pool by invoking {@link #clear()}. </p>
{@inheritDoc} <p> Successive activations of this method examine objects in sequence, cycling through objects in oldest-to-youngest order. </p>
Obtains a reference to the factory used to create, destroy and validate the objects used by this pool.
Returns the type - including the specific type rather than the generic - of the factory.
Gets whether this pool identifies and logs any abandoned objects.
Returns the cap on the number of "idle" instances in the pool. If maxIdle 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 maxIdle. The best value for maxIdle for heavily loaded system will vary but the default is a good starting point.
Returns the target for the minimum number of idle objects to maintain in the pool. This setting only has an effect if it is positive and {@link #getTimeBetweenEvictionRunsMillis()} is greater than zero. If this is the case, an attempt is made to ensure that the pool has the required minimum number of instances during idle object eviction runs. <p> If the configured value of minIdle is greater than the configured value for maxIdle then the value of maxIdle will be used instead. </p>
Returns 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.
Gets whether a check is made for abandoned objects when an object is borrowed from this pool.
Gets whether a check is made for abandoned objects when the evictor runs.
Obtains the timeout before which an object will be considered to be abandoned by this pool.
{@inheritDoc} <p> Activation of this method decrements the active count and attempts to destroy the instance. </p>
Gets whether or not abandoned object removal is configured for this pool.
Provides information on all the objects in the pool, both idle (waiting to be borrowed) and active (currently borrowed). <p> 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. </p>
Tries to ensure that {@link #getMinIdle()} idle instances are available in the pool.
{@inheritDoc} <p> If {@link #getMaxIdle() maxIdle} is set to a positive value and the number of idle instances has reached this value, the returning instance is destroyed. </p> <p> If {@link #getTestOnReturn() testOnReturn} == true, the returning instance is validated before being returned to the idle instance pool. In this case, if validation fails, the instance is destroyed. </p> <p> Exceptions encountered destroying objects for any reason are swallowed but notified via a {@link SwallowedExceptionListener}. </p>
Sets the abandoned object removal configuration.
Sets the base pool configuration.
Returns the cap on the number of "idle" instances in the pool. If maxIdle 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 maxIdle. The best value for maxIdle for heavily loaded system will vary but the default is a good starting point.
Sets the target for the minimum number of idle objects to maintain in the pool. This setting only has an effect if it is positive and {@link #getTimeBetweenEvictionRunsMillis()} is greater than zero. If this is the case, an attempt is made to ensure that the pool has the required minimum number of instances during idle object eviction runs. <p> If the configured value of minIdle is greater than the configured value for maxIdle then the value of maxIdle will be used instead. </p>
The size of the caches used to store historical data for some attributes so that rolling means may be calculated.
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.
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.
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).
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).
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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>
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.
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.
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.
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.
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).
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).
Returns the name of the {@link EvictionPolicy} implementation that is used by this pool.
Sets the eviction policy for 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.
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.
Closes the pool, destroys the remaining idle objects and, if registered in JMX, deregisters it.
Has this pool instance been closed. @return <code>true</code> when this pool has been closed.
<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 the {@link EvictionPolicy} defined for this pool.
Verifies that the pool is open. @throws IllegalStateException if the pool is closed.
<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.
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
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 successfully borrowed from this pool over the lifetime of the pool. @return the borrowed object count
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
The total number of objects created for this pool over the lifetime of the pool. @return the created object count
The total number of objects destroyed by this pool over the lifetime of the pool. @return the 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 as a result of failing validation during <code>borrowObject()</code> over the lifetime of the pool. @return validation destroyed object count
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 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
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 maximum time a thread has waited to borrow objects from the pool. @return maximum wait time in milliseconds since the pool was created
The number of instances currently idle in this pool. @return count of instances available for checkout from the pool
The listener used (if any) to receive notifications of exceptions unavoidably swallowed by the pool.
The listener used (if any) to receive notifications of exceptions unavoidably swallowed by the pool.
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
Marks the object as returning to the pool. @param pooledObject instance to return to the keyed pool
The idle object evictor {@link TimerTask}.
A configurable {@link ObjectPool} implementation. <p> When coupled with the appropriate {@link PooledObjectFactory}, <code>GenericObjectPool</code> provides robust pooling functionality for arbitrary objects.</p> <p> Optionally, one may configure the pool to examine and possibly evict objects as they sit idle in the pool and to ensure that a minimum number of idle objects are available. This is performed by an "idle object eviction" thread, which runs asynchronously. Caution should be used when configuring this optional feature. Eviction runs contend with client threads for access to objects in the pool, so if they run too frequently performance issues may result.</p> <p> The pool can also be configured to detect and remove "abandoned" objects, i.e. objects that have been checked out of the pool but neither used nor returned before the configured {@link AbandonedConfig#getRemoveAbandonedTimeout() removeAbandonedTimeout}. Abandoned object removal can be configured to happen when <code>borrowObject</code> is invoked and the pool is close to starvation, or it can be executed by the idle object evictor, or both. If pooled objects implement the {@link TrackedUse} interface, their last use will be queried using the <code>getLastUsed</code> method on that interface; otherwise abandonment is determined by how long an object has been checked out from the pool.</p> <p> 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.</p> <p> This class is intended to be thread-safe.</p>
@see GenericKeyedObjectPool
@param <T> Type of element pooled in this pool.