Top Description Inners Fields Constructors Methods
org.apache.commons.pool2

public final Class PoolUtils

extends Object
Class Inheritance
Imports
java.util.Collection, .Collections, .HashMap, .Iterator, .List, .Map, .Timer, .TimerTask, java.util.concurrent.locks.ReentrantReadWriteLock, .ReentrantReadWriteLock.ReadLock, .ReentrantReadWriteLock.WriteLock

This class consists exclusively of static methods that operate on or return ObjectPool or KeyedObjectPool related interfaces.
Since
2.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
PoolUtils.ErodingFactor

Encapsulate the logic for when the next poolable object should be discarded.

private static class
PoolUtils.ErodingKeyedObjectPool<
object pool key type
K
,
object pool value type
V
>

Decorates a keyed object pool, adding "eroding" behavior.

private static class
PoolUtils.ErodingObjectPool<
type of objects in the pool
T
>

Decorates an object pool, adding "eroding" behavior.

private static class
PoolUtils.ErodingPerKeyKeyedObjectPool<
object pool key type
K
,
object pool value type
V
>

Extends ErodingKeyedObjectPool to allow erosion to take place on a per-key basis.

private static class
PoolUtils.KeyedObjectPoolMinIdleTimerTask<
object pool key type
K
,
object pool value type
V
>

Timer task that adds objects to the pool until the number of idle instances for the given key reaches the configured minIdle.

private static class
PoolUtils.ObjectPoolMinIdleTimerTask<
type of objects in the pool
T
>

Timer task that adds objects to the pool until the number of idle instances reaches the configured minIdle.

pack-priv static class
PoolUtils.SynchronizedKeyedObjectPool<
object pool key type
K
,
object pool value type
V
>

A synchronized (thread-safe) KeyedObjectPool backed by the specified KeyedObjectPool.

private static class
PoolUtils.SynchronizedKeyedPooledObjectFactory<
pooled object factory key type
K
,
pooled object factory value type
V
>

A fully synchronized KeyedPooledObjectFactory that wraps a KeyedPooledObjectFactory and synchronizes access to the wrapped factory methods.

private static class
PoolUtils.SynchronizedObjectPool<
type of objects in the pool
T
>

A synchronized (thread-safe) ObjectPool backed by the specified ObjectPool.

private static class
PoolUtils.SynchronizedPooledObjectFactory<
pooled object factory type
T
>

A fully synchronized PooledObjectFactory that wraps a PooledObjectFactory and synchronizes access to the wrapped factory methods.

pack-priv static class
PoolUtils.TimerHolder

Timer used to periodically check pools idle object count.

Field Summary

Modifier and TypeField and Description
private static final String
private static final String
pack-priv static final String
private static final String
pack-priv static final String
private static final String

Constructor Summary

AccessConstructor and Description
public
PoolUtils()

PoolUtils instances should NOT be constructed in standard programming.

Method Summary

Modifier and TypeMethod and Description
public static <
the type of the pool key
K
,
the type of pool entries
V
>
Map<K, TimerTask>

Returns:

a Map of key and TimerTask pairs that will periodically check the pools idle object count.
checkMinIdle
(final KeyedObjectPool<K, V>
the keyedPool to check periodically.
keyedPool
,
final Collection<K>
a collection of keys to check the idle object count.
keys
,
final int
if the KeyedObjectPool#getNumIdle(Object) is less than this then add an idle object.
minIdle
,
final long
the frequency in milliseconds to check the number of idle objects in a keyedPool, see Timer#schedule(TimerTask, long, long).
periodMillis
)

Periodically check the idle object count for each key in the Collection keys in the keyedPool.

public static <
the type of the pool key
K
,
the type of pool entries
V
>
TimerTask

Returns:

the TimerTask that will periodically check the pools idle object count.
checkMinIdle
(final KeyedObjectPool<K, V>
the keyedPool to check periodically.
keyedPool
,
final K
the key to check the idle count of.
key
,
final int
if the KeyedObjectPool#getNumIdle(Object) is less than this then add an idle object.
minIdle
,
final long
the frequency in milliseconds to check the number of idle objects in a keyedPool, see Timer#schedule(TimerTask, long, long).
periodMillis
)

Periodically check the idle object count for the key in the keyedPool.

public static <
the type of objects in the pool
T
>
TimerTask

Returns:

the TimerTask that will periodically check the pools idle object count.
checkMinIdle
(final ObjectPool<T>
the pool to check periodically.
pool
,
final int
if the ObjectPool#getNumIdle() is less than this then add an idle object.
minIdle
,
final long
the frequency in milliseconds to check the number of idle objects in a pool, see Timer#schedule(TimerTask, long, long).
periodMillis
)

Periodically check the idle object count for the pool.

public static void
checkRethrow(final Throwable
The Throwable to check
t
)

Should the supplied Throwable be re-thrown (eg if it is an instance of one of the Throwables that should never be swallowed).

public static <
the type of the pool key
K
,
the type of pool entries
V
>
KeyedObjectPool<K, V>

Returns:

a pool that adaptively decreases its size when idle objects are no longer needed.
erodingPool
(final KeyedObjectPool<K, V>
the KeyedObjectPool to be decorated so it shrinks its idle count when possible.
keyedPool
)

Returns a pool that adaptively decreases its size when idle objects are no longer needed.

public static <
the type of the pool key
K
,
the type of pool entries
V
>
KeyedObjectPool<K, V>

Returns:

a pool that adaptively decreases its size when idle objects are no longer needed.
erodingPool
(final KeyedObjectPool<K, V>
the KeyedObjectPool to be decorated so it shrinks its idle count when possible.
keyedPool
,
final float
a positive value to scale the rate at which the pool tries to reduce its size. If 0 < factor < 1 then the pool shrinks more aggressively. If 1 < factor then the pool shrinks less aggressively.
factor
)

Returns a pool that adaptively decreases its size when idle objects are no longer needed.

public static <
the type of the pool key
K
,
the type of pool entries
V
>
KeyedObjectPool<K, V>

Returns:

a pool that adaptively decreases its size when idle objects are no longer needed.
erodingPool
(final KeyedObjectPool<K, V>
the KeyedObjectPool to be decorated so it shrinks its idle count when possible.
keyedPool
,
final float
a positive value to scale the rate at which the pool tries to reduce its size. If 0 < factor < 1 then the pool shrinks more aggressively. If 1 < factor then the pool shrinks less aggressively.
factor
,
final boolean
when true, each key is treated independently.
perKey
)

Returns a pool that adaptively decreases its size when idle objects are no longer needed.

public static <
the type of objects in the pool
T
>
ObjectPool<T>

Returns:

a pool that adaptively decreases its size when idle objects are no longer needed.
erodingPool
(final ObjectPool<T>
the ObjectPool to be decorated so it shrinks its idle count when possible.
pool
)

Returns a pool that adaptively decreases its size when idle objects are no longer needed.

public static <
the type of objects in the pool
T
>
ObjectPool<T>

Returns:

a pool that adaptively decreases its size when idle objects are no longer needed.
erodingPool
(final ObjectPool<T>
the ObjectPool to be decorated so it shrinks its idle count when possible.
pool
,
final float
a positive value to scale the rate at which the pool tries to reduce its size. If 0 < factor < 1 then the pool shrinks more aggressively. If 1 < factor then the pool shrinks less aggressively.
factor
)

Returns a pool that adaptively decreases its size when idle objects are no longer needed.

private static Timer

Returns:

the Timer for checking keyedPool's idle count.
getMinIdleTimer
()

Gets the Timer for checking keyedPool's idle count.

public static <
the type of the pool key
K
,
the type of pool entries
V
>
void
prefill(final KeyedObjectPool<K, V>
the keyedPool to prefill.
keyedPool
,
final Collection<K>
Collection of keys to add objects for.
keys
,
final int
the number of idle objects to add for each key.
count
)

Calls KeyedObjectPool#addObject(Object) on keyedPool with each key in keys for count number of times.
public static <
the type of the pool key
K
,
the type of pool entries
V
>
void
prefill(final KeyedObjectPool<K, V>
the keyedPool to prefill.
keyedPool
,
final K
the key to add objects for.
key
,
final int
the number of idle objects to add for key.
count
)

Calls KeyedObjectPool#addObject(Object) on keyedPool with key count number of times.
public static <
the type of objects in the pool
T
>
void
prefill(final ObjectPool<T>
the pool to prefill.
pool
,
final int
the number of idle objects to add.
count
)

Deprecated Use ObjectPool#addObjects(int).
Calls ObjectPool#addObject() on pool count number of times.
public static <
the type of the pool key
K
,
the type of pool entries
V
>
KeyedPooledObjectFactory<K, V>

Returns:

a synchronized view of the specified KeyedPooledObjectFactory.
synchronizedKeyedPooledFactory
(final KeyedPooledObjectFactory<K, V>
the KeyedPooledObjectFactory to be "wrapped" in a synchronized KeyedPooledObjectFactory.
keyedFactory
)

Returns a synchronized (thread-safe) KeyedPooledObjectFactory backed by the specified KeyedPooledObjectFactory.

public static <
the type of the pool key
K
,
the type of pool entries
V
>
KeyedObjectPool<K, V>

Returns:

a synchronized view of the specified KeyedObjectPool.
synchronizedPool
(final KeyedObjectPool<K, V>
the KeyedObjectPool to be "wrapped" in a synchronized KeyedObjectPool.
keyedPool
)

Returns a synchronized (thread-safe) KeyedObjectPool backed by the specified KeyedObjectPool.

public static <
the type of objects in the pool
T
>
ObjectPool<T>

Returns:

a synchronized view of the specified ObjectPool.
synchronizedPool
(final ObjectPool<T>
the ObjectPool to be "wrapped" in a synchronized ObjectPool.
pool
)

Returns a synchronized (thread-safe) ObjectPool backed by the specified ObjectPool.

public static <
the type of objects in the pool
T
>
PooledObjectFactory<T>

Returns:

a synchronized view of the specified PooledObjectFactory.
synchronizedPooledFactory
(final PooledObjectFactory<T>
the PooledObjectFactory to be "wrapped" in a synchronized PooledObjectFactory.
factory
)

Returns a synchronized (thread-safe) PooledObjectFactory backed by the specified PooledObjectFactory.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait