BaseGenericObjectPool

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.

abstract
class BaseGenericObjectPool : BaseObject {}

Constructors

this
this(BaseObjectPoolConfig config, string jmxNameBase, string jmxNamePrefix)

Handles JMX registration (if required) and the initialization required for monitoring.

Members

Classes

Evictor
class Evictor

The idle object evictor {@link TimerTask}.

Functions

assertOpen
void assertOpen()

Verifies that the pool is open. @throws IllegalStateException if the pool is closed.

close
void close()

Closes the pool, destroys the remaining idle objects and, if registered in JMX, deregisters it.

ensureMinIdle
void ensureMinIdle()

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

evict
void evict()

<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>

getBlockWhenExhausted
bool getBlockWhenExhausted()

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).

getBorrowedCount
long getBorrowedCount()

The total number of objects successfully borrowed from this pool over the lifetime of the pool. @return the borrowed object count

getCreatedCount
long getCreatedCount()

The total number of objects created for this pool over the lifetime of the pool. @return the created object count

getCreationStackTrace
string getCreationStackTrace()

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

getDestroyedByBorrowValidationCount
long getDestroyedByBorrowValidationCount()

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

getDestroyedByEvictorCount
long getDestroyedByEvictorCount()

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

getDestroyedCount
long getDestroyedCount()

The total number of objects destroyed by this pool over the lifetime of the pool. @return the destroyed object count

getEvictionPolicy
EvictionPolicy getEvictionPolicy()

Returns the {@link EvictionPolicy} defined for this pool.

getEvictionPolicyClassName
string getEvictionPolicyClassName()

Returns the name of the {@link EvictionPolicy} implementation that is used by this pool.

getEvictorShutdownTimeoutMillis
long getEvictorShutdownTimeoutMillis()

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.

getFairness
bool getFairness()

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.

getLifo
bool getLifo()

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.

getMaxBorrowWaitTimeMillis
long getMaxBorrowWaitTimeMillis()

The maximum time a thread has waited to borrow objects from the pool. @return maximum wait time in milliseconds since the pool was created

getMaxTotal
int getMaxTotal()

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.

getMaxWaitMillis
long getMaxWaitMillis()

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.

getMeanActiveTimeMillis
long getMeanActiveTimeMillis()

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

getMeanBorrowWaitTimeMillis
long getMeanBorrowWaitTimeMillis()

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

getMeanIdleTimeMillis
long getMeanIdleTimeMillis()

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

getMinEvictableIdleTimeMillis
long getMinEvictableIdleTimeMillis()

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.

getNumIdle
int getNumIdle()

The number of instances currently idle in this pool. @return count of instances available for checkout from the pool

getNumTestsPerEvictionRun
int getNumTestsPerEvictionRun()

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.

getReturnedCount
long getReturnedCount()

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

getSoftMinEvictableIdleTimeMillis
long getSoftMinEvictableIdleTimeMillis()

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).

getSwallowedExceptionListener
SwallowedExceptionListener getSwallowedExceptionListener()

The listener used (if any) to receive notifications of exceptions unavoidably swallowed by the pool.

getTestOnBorrow
bool getTestOnBorrow()

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.

getTestOnCreate
bool getTestOnCreate()

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.

getTestOnReturn
bool getTestOnReturn()

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.

getTestWhileIdle
bool getTestWhileIdle()

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.

getTimeBetweenEvictionRunsMillis
long getTimeBetweenEvictionRunsMillis()

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.

isClosed
bool isClosed()

Has this pool instance been closed. @return <code>true</code> when this pool has been closed.

markReturningState
void markReturningState(IPooledObject pooledObject)

Marks the object as returning to the pool. @param pooledObject instance to return to the keyed pool

setBlockWhenExhausted
void setBlockWhenExhausted(bool blockWhenExhausted)

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).

setConfig
void setConfig(BaseObjectPoolConfig conf)
Undocumented in source. Be warned that the author may not have intended to support it.
setEvictionPolicy
void setEvictionPolicy(EvictionPolicy evictionPolicy)

Sets the eviction policy for this pool.

setEvictorShutdownTimeoutMillis
void setEvictorShutdownTimeoutMillis(long evictorShutdownTimeoutMillis)

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.

setLifo
void setLifo(bool lifo)

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.

setMaxTotal
void setMaxTotal(int maxTotal)

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.

setMaxWaitMillis
void setMaxWaitMillis(long maxWaitMillis)

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.

setMinEvictableIdleTimeMillis
void setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis)

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.

setNumTestsPerEvictionRun
void setNumTestsPerEvictionRun(int numTestsPerEvictionRun)

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.

setSoftMinEvictableIdleTimeMillis
void setSoftMinEvictableIdleTimeMillis(long softMinEvictableIdleTimeMillis)

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).

setSwallowedExceptionListener
void setSwallowedExceptionListener(SwallowedExceptionListener swallowedExceptionListener)

The listener used (if any) to receive notifications of exceptions unavoidably swallowed by the pool.

setTestOnBorrow
void setTestOnBorrow(bool testOnBorrow)

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.

setTestOnCreate
void setTestOnCreate(bool testOnCreate)

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.

setTestOnReturn
void setTestOnReturn(bool testOnReturn)

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.

setTestWhileIdle
void setTestWhileIdle(bool testWhileIdle)

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.

setTimeBetweenEvictionRunsMillis
void setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis)

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>

startEvictor
void startEvictor(long delay)

<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>

stopEvitor
void stopEvitor()

Stops the evictor.

swallowException
void swallowException(Exception swallowException)

Swallows an exception and notifies the configured listener for swallowed exceptions queue.

toStringAppendFields
void toStringAppendFields(StringBuilder builder)
Undocumented in source. Be warned that the author may not have intended to support it.
updateStatsBorrow
void updateStatsBorrow(IPooledObject p, long waitTime)

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

updateStatsReturn
void updateStatsReturn(long activeTime)

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

Variables

MEAN_TIMING_STATS_CACHE_SIZE
enum int MEAN_TIMING_STATS_CACHE_SIZE;

The size of the caches used to store historical data for some attributes so that rolling means may be calculated.

closeLock
Object closeLock;
Undocumented in source.
closed
bool closed;
Undocumented in source.
createdCount
long createdCount;
Undocumented in source.
destroyedByBorrowValidationCount
long destroyedByBorrowValidationCount;
Undocumented in source.
destroyedByEvictorCount
long destroyedByEvictorCount;
Undocumented in source.
destroyedCount
long destroyedCount;
Undocumented in source.
evictionIterator
EvictionIterator evictionIterator;
Undocumented in source.
evictionLock
Object evictionLock;
Undocumented in source.

Inherited Members

From BaseObject

toString
string toString()
Undocumented in source. Be warned that the author may not have intended to support it.
toStringAppendFields
void toStringAppendFields(StringBuilder builder)

Used by sub-classes to include the fields defined by the sub-class in the {@link #toString()} output.

Meta