public final class PoolUtils extends Object
Modifier and Type | Field and Description |
---|---|
static String |
MSG_NULL_KEY |
static String |
MSG_NULL_KEYS |
Constructor and Description |
---|
PoolUtils()
PoolUtils instances should NOT be constructed in standard programming.
|
Modifier and Type | Method and Description |
---|---|
static <K,V> Map<K,TimerTask> |
checkMinIdle(KeyedObjectPool<K,V> keyedPool,
Collection<K> keys,
int minIdle,
long period)
Periodically check the idle object count for each key in the
Collection keys in the keyedPool. |
static <K,V> TimerTask |
checkMinIdle(KeyedObjectPool<K,V> keyedPool,
K key,
int minIdle,
long period)
Periodically check the idle object count for the key in the keyedPool.
|
static <T> TimerTask |
checkMinIdle(ObjectPool<T> pool,
int minIdle,
long period)
Periodically check the idle object count for the pool.
|
static void |
checkRethrow(Throwable t)
Should the supplied Throwable be re-thrown (eg if it is an instance of
one of the Throwables that should never be swallowed).
|
static <K,V> void |
prefill(KeyedObjectPool<K,V> keyedPool,
Collection<K> keys,
int count)
Deprecated.
|
static <K,V> void |
prefill(KeyedObjectPool<K,V> keyedPool,
K key,
int count)
Deprecated.
|
static <T> void |
prefill(ObjectPool<T> pool,
int count)
Deprecated.
|
static <K,V> KeyedPooledObjectFactory<K,V> |
synchronizedKeyedPooledFactory(KeyedPooledObjectFactory<K,V> keyedFactory)
Returns a synchronized (thread-safe) KeyedPooledObjectFactory backed by
the specified KeyedPoolableObjectFactory.
|
static <T> PooledObjectFactory<T> |
synchronizedPooledFactory(PooledObjectFactory<T> factory)
Returns a synchronized (thread-safe) PooledObjectFactory backed by the
specified PooledObjectFactory.
|
public static final String MSG_NULL_KEY
public static final String MSG_NULL_KEYS
public PoolUtils()
public static void checkRethrow(Throwable t)
t
- The Throwable to checkThreadDeath
- if that is passed inVirtualMachineError
- if that is passed inpublic static <T> TimerTask checkMinIdle(ObjectPool<T> pool, int minIdle, long period) throws IllegalArgumentException
ObjectPool.addObject()
then no more checks will be performed.T
- the type of objects in the poolpool
- the pool to check periodically.minIdle
- if the ObjectPool.getNumIdle()
is less than this then
add an idle object.period
- the frequency to check the number of idle objects in a pool,
see Timer.schedule(TimerTask, long, long)
.TimerTask
that will periodically check the pools idle
object count.IllegalArgumentException
- when pool
is null
or when minIdle
is
negative or when period
isn't valid for
Timer.schedule(TimerTask, long, long)
public static <K,V> TimerTask checkMinIdle(KeyedObjectPool<K,V> keyedPool, K key, int minIdle, long period) throws IllegalArgumentException
KeyedObjectPool.addObject(Object)
then no more
checks for that key will be performed.K
- the type of the pool keyV
- the type of pool entrieskeyedPool
- the keyedPool to check periodically.key
- the key to check the idle count of.minIdle
- if the KeyedObjectPool.getNumIdle(Object)
is less than
this then add an idle object.period
- the frequency to check the number of idle objects in a
keyedPool, see Timer.schedule(TimerTask, long, long)
.TimerTask
that will periodically check the pools idle
object count.IllegalArgumentException
- when keyedPool
, key
is null
or
when minIdle
is negative or when period
isn't
valid for Timer.schedule(TimerTask, long, long)
.public static <K,V> Map<K,TimerTask> checkMinIdle(KeyedObjectPool<K,V> keyedPool, Collection<K> keys, int minIdle, long period) throws IllegalArgumentException
Collection keys
in the keyedPool. At most one idle object will be
added per period.K
- the type of the pool keyV
- the type of pool entrieskeyedPool
- the keyedPool to check periodically.keys
- a collection of keys to check the idle object count.minIdle
- if the KeyedObjectPool.getNumIdle(Object)
is less than
this then add an idle object.period
- the frequency to check the number of idle objects in a
keyedPool, see Timer.schedule(TimerTask, long, long)
.Map
of key and TimerTask
pairs that will
periodically check the pools idle object count.IllegalArgumentException
- when keyedPool
, keys
, or any of the values in
the collection is null
or when minIdle
is
negative or when period
isn't valid for
Timer.schedule(TimerTask, long, long)
.checkMinIdle(KeyedObjectPool, Object, int, long)
@Deprecated public static <T> void prefill(ObjectPool<T> pool, int count) throws Exception, IllegalArgumentException
ObjectPool.addObjects(int)
.T
- the type of objects in the poolpool
- the pool to prefill.count
- the number of idle objects to add.Exception
- when ObjectPool.addObject()
fails.IllegalArgumentException
- when pool
is null
.@Deprecated public static <K,V> void prefill(KeyedObjectPool<K,V> keyedPool, K key, int count) throws Exception, IllegalArgumentException
KeyedObjectPool.addObjects(Object, int)
.K
- the type of the pool keyV
- the type of pool entrieskeyedPool
- the keyedPool to prefill.key
- the key to add objects for.count
- the number of idle objects to add for key
.Exception
- when KeyedObjectPool.addObject(Object)
fails.IllegalArgumentException
- when keyedPool
or key
is null
.@Deprecated public static <K,V> void prefill(KeyedObjectPool<K,V> keyedPool, Collection<K> keys, int count) throws Exception, IllegalArgumentException
KeyedObjectPool.addObjects(Collection, int)
.KeyedObjectPool.addObject(Object)
on keyedPool
with
each key in keys
for count
number of times. This has
the same effect as calling prefill(KeyedObjectPool, Object, int)
for each key in the keys
collection.K
- the type of the pool keyV
- the type of pool entrieskeyedPool
- the keyedPool to prefill.keys
- Collection
of keys to add objects for.count
- the number of idle objects to add for each key
.Exception
- when KeyedObjectPool.addObject(Object)
fails.IllegalArgumentException
- when keyedPool
, keys
, or any value in
keys
is null
.prefill(KeyedObjectPool, Object, int)
public static <T> PooledObjectFactory<T> synchronizedPooledFactory(PooledObjectFactory<T> factory)
T
- the type of objects in the poolfactory
- the PooledObjectFactory to be "wrapped" in a synchronized
PooledObjectFactory.public static <K,V> KeyedPooledObjectFactory<K,V> synchronizedKeyedPooledFactory(KeyedPooledObjectFactory<K,V> keyedFactory)
K
- the type of the pool keyV
- the type of pool entrieskeyedFactory
- the KeyedPooledObjectFactory to be "wrapped" in a
synchronized KeyedPooledObjectFactory.Copyright © 2000-2020 Apache Software Foundation. All Rights Reserved.