GenericObjectPool
and GenericKeyedObjectPool. The primary reason this class exists is
reduce code duplication between the two pool implementations.
Concrete implementations of this class are expected to be thread-safe.
| Modifier and Type | Class and Description |
|---|---|
| pack-priv class | BaseGenericObjectPool.EvictionIterator
The idle object eviction iterator. |
| pack-priv class | BaseGenericObjectPool.Evictor
The idle object evictor |
| pack-priv static class | BaseGenericObjectPool.IdentityWrapper<
type of objects in the pool T>Wrapper for objects under management by the pool. |
| private static class | BaseGenericObjectPool.StatsStore
Maintains a cache of values for a single metric and reports statistics on the cached values. |
| Modifier and Type | Field and Description |
|---|---|
| protected volatile AbandonedConfig | abandonedConfig
Additional configuration properties for abandoned object tracking. |
| private final BaseGenericObjectPool. | |
| private volatile boolean | |
| private final AtomicLong | |
| pack-priv volatile boolean | |
| pack-priv final Object | |
| pack-priv final AtomicLong | |
| private final String | |
| private static final Duration | |
| pack-priv final AtomicLong | |
| pack-priv final AtomicLong | |
| pack-priv final AtomicLong | |
| private volatile Duration | |
| private static final String | |
| pack-priv BaseGenericObjectPool | |
| pack-priv final Object | |
| private volatile EvictionPolicy | |
| private BaseGenericObjectPool | |
| private volatile Duration | |
| private final WeakReference | factoryClassLoader
Class loader for evictor thread to use since, in a JavaEE or similar environment, the context class loader for the evictor thread may not have visibility of the correct factory. |
| private final boolean | |
| private final BaseGenericObjectPool. | |
| private volatile boolean | |
| private final AtomicReference | |
| private volatile int | |
| private volatile Duration | |
| public static final 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. |
| private volatile boolean | |
| private volatile Duration | |
| private volatile int | |
| private final ObjectName | |
| private final AtomicLong | |
| private volatile Duration | |
| private volatile SwallowedExceptionListener | |
| private volatile boolean | |
| private volatile boolean | |
| private volatile boolean | |
| private volatile boolean | |
| private final BaseGenericObjectPool. |
| Access | Constructor and Description |
|---|---|
| public | BaseGenericObjectPool(final BaseObjectPoolConfig<T>
Pool configuration config, final String The default base JMX name for the new pool unless
overridden by the config jmxNameBase, final String Prefix to be used for JMX name for the new pool jmxNamePrefix)Handles JMX registration (if required) and the initialization required for monitoring. |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv String | Returns: The root string plus statistics.The root string. string)Appends statistics if enabled. |
| pack-priv final void | |
| public abstract void | close()
Redeclares java. |
| pack-priv ArrayList | Returns: a list of pooled objects to remove based on their state.The abandoned configuration. abandonedConfig, final Map<BaseGenericObjectPool.PooledObject instances to consider. allObjectsCreates a list of pooled objects to remove based on their state. |
| pack-priv abstract void | ensureMinIdle()
Tries to ensure that the configured minimum number of idle instances are available in the pool. |
| public abstract void | evict()
Perform |
| public final boolean | Returns: true if borrowObject() should block
when the pool is exhaustedGets whether to block when the |
| public final long | Returns: the borrowed object countGets the total number of objects successfully borrowed from this pool over the lifetime of the pool. |
| public final long | Returns: the created object countGets the total number of objects created for this pool over the lifetime of the pool. |
| public final String | Returns: pool creation stack traceGets the stack trace for the call that created this pool. |
| public final long | Returns: validation destroyed object countGets the total number of objects destroyed by this pool as a result of failing
validation during |
| public final long | Returns: the evictor destroyed object countGets the total number of objects destroyed by the evictor associated with this pool over the lifetime of the pool. |
| public final long | Returns: the destroyed object countGets the total number of objects destroyed by this pool over the lifetime of the pool. |
| public final Duration | Returns: number of milliseconds to sleep between evictor runsGets the duration to sleep between runs of the idle object evictor thread. |
| public EvictionPolicy | |
| public final String | Returns: The fully qualified class name of theEvictionPolicyGets the name of the |
| public final Duration | Returns: The timeout that will be used while waiting for the Evictor to shut down.
Deprecated
Use
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.
getEvictorShutdownTimeoutDuration().
|
| public final Duration | Returns: The timeout that will be used while waiting for the Evictor to shut down.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. |
| public final long | Returns: The timeout in milliseconds that will be used while waiting for the Evictor to shut down.
Deprecated
Use
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.
getEvictorShutdownTimeoutDuration().
|
| public final boolean | Returns: true if waiting threads are to be served
by the pool in arrival orderGets whether or not the pool serves threads waiting to borrow objects fairly. |
| public final ObjectName | Returns: the JMX nameGets the name under which the pool has been registered with the
platform MBean server or |
| public final boolean | Returns: true if the pool is configured with LIFO behavior
or false if the pool is configured with FIFO
behaviorGets whether the pool has LIFO (last in, first out) behavior 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. |
| public boolean | Returns: true if abandoned object removal is configured for this
pool and removal events are to be logged otherwise falseGets whether this pool identifies and logs any abandoned objects. |
| public final Duration | Returns: maximum wait time in milliseconds since the pool was createdGets the maximum time a thread has waited to borrow objects from the pool. |
| public final long | Returns: maximum wait time in milliseconds since the pool was created
Deprecated
Use
Gets the maximum time a thread has waited to borrow objects from the pool.
getMaxBorrowWaitDuration().
|
| public final int | Returns: the cap on the total number of object instances managed by the pool.Gets the maximum number of objects that can be allocated by the pool (checked out to clients, or idle awaiting checkout) at a given time. |
| public final Duration | Returns: the maximum number of millisecondsborrowObject()
will block.Gets the maximum duration the
|
| public final long | Returns: the maximum number of millisecondsborrowObject()
will block.
Deprecated
Use
Gets the maximum amount of time (in milliseconds) the
getMaxWaitDuration().
borrowObject() method should block before throwing an
exception when the pool is exhausted and
getBlockWhenExhausted is true.
|
| public final Duration | Returns: mean time an object has been checked out from the pool among recently returned objects.Gets the mean time objects are active for based on the last |
| public final long | Returns: mean time an object has been checked out from the pool among recently returned objects.
Deprecated
Use
Gets the mean time objects are active for based on the last getMeanActiveDuration().
MEAN_TIMING_STATS_CACHE_SIZE objects returned to the pool.
|
| public final Duration | Returns: mean time in milliseconds that a recently served thread has had to wait to borrow an object from the pool.Gets the mean time threads wait to borrow an object based on the last |
| public final long | Returns: mean time in milliseconds that a recently served thread has had to wait to borrow an object from the pool.
Deprecated
Use
Gets the mean time threads wait to borrow an object based on the last getMeanBorrowWaitDuration().
MEAN_TIMING_STATS_CACHE_SIZE objects borrowed from the pool.
|
| public final Duration | Returns: mean time an object has been idle in the pool among recently borrowed objects.Gets the mean time objects are idle for based on the last |
| public final long | Returns: mean time an object has been idle in the pool among recently borrowed objects.
Deprecated
Use
Gets the mean time objects are idle for based on the last getMeanIdleDuration().
MEAN_TIMING_STATS_CACHE_SIZE objects borrowed from the pool.
|
| public boolean | Returns: whether to include statistics in exception messages.Gets whether to include statistics in exception messages. |
| public final Duration | Returns: minimum amount of time an object may sit idle in the pool before it is eligible for evictionGets 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 |
| public final Duration | Returns: minimum amount of time an object may sit idle in the pool before it is eligible for eviction
Deprecated
Use
Gets 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 getMinEvictableIdleDuration().
setDurationBetweenEvictionRuns(Duration)).
|
| public final long | Returns: minimum amount of time an object may sit idle in the pool before it is eligible for eviction
Deprecated
Use
Gets 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 getMinEvictableIdleDuration().
setTimeBetweenEvictionRunsMillis(long)).
|
| public abstract int | Returns: count of instances available for checkout from the poolGets the number of instances currently idle in this pool. |
| public final int | Returns: max number of objects to examine during each evictor runGets the maximum number of objects to examine during each run (if any) of the idle object evictor thread. |
| public boolean | Returns: true if abandoned object removal is configured to be
activated by borrowObject otherwise falseGets whether a check is made for abandoned objects when an object is borrowed from this pool. |
| public boolean | Returns: true if abandoned object removal is configured to be
activated when the evictor runs otherwise falseGets whether a check is made for abandoned objects when the evictor runs. |
| public int | Returns: The abandoned object timeout in seconds if abandoned object removal is configured for this pool; Integer.MAX_VALUE otherwise.
Deprecated
Use
Gets the timeout before which an object will be considered to be
abandoned by this pool.
getRemoveAbandonedTimeoutDuration().
|
| public Duration | Returns: The abandoned object timeout in seconds if abandoned object removal is configured for this pool; Integer.MAX_VALUE otherwise.Gets the timeout before which an object will be considered to be abandoned by this pool. |
| public final long | Returns: the returned object countGets the total number of objects returned to this pool over the lifetime of the pool. |
| public final Duration | Returns: minimum amount of time an object may sit idle in the pool before it is eligible for eviction if minIdle instances are availableGets 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 |
| public final Duration | Returns: minimum amount of time an object may sit idle in the pool before it is eligible for eviction if minIdle instances are available
Deprecated
Use
Gets 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 getSoftMinEvictableIdleDuration.
setDurationBetweenEvictionRuns(Duration)),
with the extra condition that at least minIdle object
instances remain in the pool.
|
| public final long | Returns: minimum amount of time an object may sit idle in the pool before it is eligible for eviction if minIdle instances are available
Deprecated
Use
Gets 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 getSoftMinEvictableIdleTime().
setTimeBetweenEvictionRunsMillis(long)),
with the extra condition that at least minIdle object
instances remain in the pool.
|
| private String | Returns: exception stack trace as a stringexception to trace e)Gets the stack trace of an exception as a string. |
| pack-priv String | |
| public final SwallowedExceptionListener | Returns: The listener ornull for no listenerGets the listener used (if any) to receive notifications of exceptions unavoidably swallowed by the pool. |
| public final boolean | Returns: true if objects are validated before being returned
from the borrowObject() methodGets whether objects borrowed from the pool will be validated before
being returned from the |
| public final boolean | Returns: true if newly created objects are validated before
being returned from the borrowObject() methodGets whether objects created for the pool will be validated before
being returned from the |
| public final boolean | Returns: true if objects are validated on return to
the pool via the returnObject() methodGets whether objects borrowed from the pool will be validated when
they are returned to the pool via the |
| public final boolean | Returns: true if objects will be validated by the evictorGets whether objects sitting idle in the pool will be validated by the
idle object evictor (if any - see
|
| public final Duration | Returns: number of milliseconds to sleep between evictor runs
Deprecated
Gets the duration to sleep between runs of the idle
object evictor thread.
getDurationBetweenEvictionRuns().
|
| public final long | Returns: number of milliseconds to sleep between evictor runs
Deprecated
Use
Gets the number of milliseconds to sleep between runs of the idle
object evictor thread.
getDurationBetweenEvictionRuns().
|
| public boolean | Returns: true if this pool is configured to detect and remove abandoned objectsTests whether or not abandoned object removal is configured for this pool. |
| public final boolean | Returns: true when this pool has been closed.Tests whether this pool instance been closed. |
| private ObjectName | Returns: registered ObjectName, null if registration failsPool configuration config, final String default base JMX name for this pool jmxNameBase, String name prefix jmxNamePrefix)Registers the pool with the platform MBean server. |
| pack-priv final void | |
| protected void | markReturningState(final PooledObject<T>
instance to return to the keyed pool pooledObject)Marks the object as returning to the pool. |
| public void | setAbandonedConfig(final AbandonedConfig
the new configuration to use. This is used by value. abandonedConfig)Sets the abandoned object removal configuration. |
| public final void | setBlockWhenExhausted(final boolean
true if
borrowObject() should block
when the pool is exhaustedSets whether to block when the |
| protected void | setConfig(final BaseObjectPoolConfig<T>
Initialization source. config)Sets the receiver with the given configuration. |
| public final void | setDurationBetweenEvictionRuns(final Duration
duration to sleep between evictor runs timeBetweenEvictionRuns)Sets the number of milliseconds to sleep between runs of the idle object evictor thread. |
| public void | setEvictionPolicy(final EvictionPolicy<T>
the eviction policy for this pool. evictionPolicy)Sets the eviction policy for this pool. |
| private void | setEvictionPolicy(final String
Eviction policy class name. className, final ClassLoader Load the class from this class loader. classLoader)Sets the eviction policy. |
| public final void | setEvictionPolicyClassName(final String
the fully qualified class name of the new eviction policy evictionPolicyClassName)Sets the name of the |
| public final void | setEvictionPolicyClassName(final String
the fully qualified class name of the new eviction policy evictionPolicyClassName, final ClassLoader the class loader to load the given classLoader)evictionPolicyClassName.Sets the name of the |
| public final void | setEvictorShutdownTimeout(final Duration
the timeout in milliseconds that will be used while waiting for the Evictor
to shut down. evictorShutdownTimeout)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 value for the Evictor. |
| public final void | setEvictorShutdownTimeoutMillis(final long
the timeout in milliseconds that will be used while waiting for the Evictor
to shut down. evictorShutdownTimeoutMillis)
Deprecated
Use
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 value for the Evictor.
setEvictorShutdownTimeout(Duration).
|
| public final void | setLifo(final boolean
true if the pool is to be configured with LIFO
behavior or false if the pool is to be
configured with FIFO behaviorSets whether the pool has LIFO (last in, first out) behavior 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. |
| public final void | setMaxTotal(final int
The cap on the total number of object instances managed
by the pool. Negative values mean that there is no limit
to the number of objects allocated by the pool. 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. |
| public final void | setMaxWait(final Duration
the maximum duration
maxWaitDuration)borrowObject() will block or negative
for indefinitely.Sets the maximum duration the
|
| public final void | setMaxWaitMillis(final long
the maximum number of milliseconds
maxWaitMillis)borrowObject() will block or negative
for indefinitely.
Deprecated
Use
Sets the maximum amount of time (in milliseconds) the
setMaxWait.
borrowObject() method should block before throwing an
exception when the pool is exhausted and
getBlockWhenExhausted is true.
|
| public void | setMessagesStatistics(final boolean
whether to include statistics in exception messages. messagesDetails)Sets whether to include statistics in exception messages. |
| public final void | setMinEvictableIdle(final Duration
minimum amount of time an object may sit idle in the pool
before it is eligible for eviction minEvictableIdleTime)
Deprecated
Use
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 setMinEvictableIdleDuration(Duration).
setDurationBetweenEvictionRuns(Duration)).
|
| public final void | setMinEvictableIdleDuration(final Duration
minimum amount of time an object may sit idle in the pool
before it is eligible for eviction minEvictableIdleTime)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 |
| public final void | setMinEvictableIdleTime(final Duration
minimum amount of time an object may sit idle in the pool
before it is eligible for eviction minEvictableIdleTime)
Deprecated
Use
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 setMinEvictableIdleDuration(Duration).
setDurationBetweenEvictionRuns(Duration)).
|
| public final void | setMinEvictableIdleTimeMillis(final long
minimum amount of time an object may sit idle in the pool
before it is eligible for eviction minEvictableIdleTimeMillis)
Deprecated
Use
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 setMinEvictableIdleTime(Duration).
setTimeBetweenEvictionRunsMillis(long)).
|
| public final void | setNumTestsPerEvictionRun(final int
max number of objects to examine during each evictor run numTestsPerEvictionRun)Sets the maximum number of objects to examine during each run (if any) of the idle object evictor thread. |
| public final void | setSoftMinEvictableIdle(final Duration
minimum amount of time an object may sit idle in the pool
before it is eligible for eviction if minIdle instances are
available softMinEvictableIdleTime)
Deprecated
Use
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 setSoftMinEvictableIdleDuration(Duration).
setDurationBetweenEvictionRuns(Duration)),
with the extra condition that at least minIdle object
instances remain in the pool.
|
| public final void | setSoftMinEvictableIdleDuration(final Duration
minimum amount of time an object may sit idle in the pool
before it is eligible for eviction if minIdle instances are
available softMinEvictableIdleTime)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 |
| public final void | setSoftMinEvictableIdleTime(final Duration
minimum amount of time an object may sit idle in the pool
before it is eligible for eviction if minIdle instances are
available softMinEvictableIdleTime)
Deprecated
Use
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 setSoftMinEvictableIdleDuration(Duration).
setDurationBetweenEvictionRuns(Duration)),
with the extra condition that at least minIdle object
instances remain in the pool.
|
| public final void | setSoftMinEvictableIdleTimeMillis(final long
minimum amount of time an object may sit idle in the pool
before it is eligible for eviction if minIdle instances are
available softMinEvictableIdleTimeMillis)
Deprecated
Use
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 setSoftMinEvictableIdleDuration(Duration).
setTimeBetweenEvictionRunsMillis(long)),
with the extra condition that at least minIdle object
instances remain in the pool.
|
| public final void | setSwallowedExceptionListener(final SwallowedExceptionListener
The listener or swallowedExceptionListener)null
for no listenerSets the listener used (if any) to receive notifications of exceptions unavoidably swallowed by the pool. |
| public final void | setTestOnBorrow(final boolean
true if objects should be validated
before being returned from the
borrowObject() methodSets whether objects borrowed from the pool will be validated before
being returned from the |
| public final void | setTestOnCreate(final boolean
true if newly created objects should be
validated before being returned from the
borrowObject() methodSets whether objects created for the pool will be validated before
being returned from the |
| public final void | setTestOnReturn(final boolean
true if objects are validated on
return to the pool via the
returnObject() methodSets whether objects borrowed from the pool will be validated when
they are returned to the pool via the |
| public final void | setTestWhileIdle(final boolean
true so objects will be validated by the evictorSets whether objects sitting idle in the pool will be validated by the
idle object evictor (if any - see
|
| public final void | setTimeBetweenEvictionRuns(final Duration
duration to sleep between evictor runs timeBetweenEvictionRuns)
Deprecated
Use
Sets the number of milliseconds to sleep between runs of the idle object evictor thread.
setDurationBetweenEvictionRuns(Duration).
|
| public final void | setTimeBetweenEvictionRunsMillis(final long
number of milliseconds to sleep between evictor runs timeBetweenEvictionRunsMillis)
Deprecated
Use
Sets the number of milliseconds to sleep between runs of the idle object evictor thread.
setDurationBetweenEvictionRuns(Duration).
|
| pack-priv final void | startEvictor(final Duration
time in milliseconds before start and between eviction runs delay)Starts the evictor with the given delay. |
| pack-priv void | |
| pack-priv final void | swallowException(final Exception
exception to be swallowed swallowException)Swallows an exception and notifies the configured listener for swallowed exceptions queue. |
| protected void | toStringAppendFields(final StringBuilder
Field names and values are appended to this object builder)Overrides org. toString() output.
|
| pack-priv final void | updateStatsBorrow(final PooledObject<T>
object borrowed from the pool p, final Duration that the borrowing thread had to wait waitDuration)Updates statistics after an object is borrowed from the pool. |
| pack-priv final void | updateStatsReturn(final Duration
the amount of time (in milliseconds) that the returning
object was checked out activeTime)Updates statistics after an object is returned to the pool. |