Package org.apache.tomcat.dbcp.pool2
Class PoolUtils
- java.lang.Object
-
- org.apache.tomcat.dbcp.pool2.PoolUtils
-
public final class PoolUtils extends Object
This class consists exclusively of static methods that operate on or return ObjectPool or KeyedObjectPool related interfaces.- Since:
- 2.0
-
-
Field Summary
Fields Modifier and Type Field Description static StringMSG_NULL_KEYstatic StringMSG_NULL_KEYS
-
Constructor Summary
Constructors Constructor Description PoolUtils()PoolUtils instances should NOT be constructed in standard programming.
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method 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 theCollection keysin the keyedPool.static <K,V>
TimerTaskcheckMinIdle(KeyedObjectPool<K,V> keyedPool, K key, int minIdle, long period)Periodically check the idle object count for the key in the keyedPool.static <T> TimerTaskcheckMinIdle(ObjectPool<T> pool, int minIdle, long period)Periodically check the idle object count for the pool.static voidcheckRethrow(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>
voidprefill(KeyedObjectPool<K,V> keyedPool, Collection<K> keys, int count)Deprecated.static <K,V>
voidprefill(KeyedObjectPool<K,V> keyedPool, K key, int count)Deprecated.static <T> voidprefill(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.
-
-
-
Field Detail
-
MSG_NULL_KEY
public static final String MSG_NULL_KEY
- See Also:
- Constant Field Values
-
MSG_NULL_KEYS
public static final String MSG_NULL_KEYS
- See Also:
- Constant Field Values
-
-
Method Detail
-
checkRethrow
public 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). Used by the pool error handling for operations that throw exceptions that normally need to be ignored.- Parameters:
t- The Throwable to check- Throws:
ThreadDeath- if that is passed inVirtualMachineError- if that is passed in
-
checkMinIdle
public static <T> TimerTask checkMinIdle(ObjectPool<T> pool, int minIdle, long period) throws IllegalArgumentException
Periodically check the idle object count for the pool. At most one idle object will be added per period. If there is an exception when callingObjectPool.addObject()then no more checks will be performed.- Type Parameters:
T- the type of objects in the pool- Parameters:
pool- the pool to check periodically.minIdle- if theObjectPool.getNumIdle()is less than this then add an idle object.period- the frequency to check the number of idle objects in a pool, seeTimer.schedule(TimerTask, long, long).- Returns:
- the
TimerTaskthat will periodically check the pools idle object count. - Throws:
IllegalArgumentException- whenpoolisnullor whenminIdleis negative or whenperiodisn't valid forTimer.schedule(TimerTask, long, long)
-
checkMinIdle
public static <K,V> TimerTask checkMinIdle(KeyedObjectPool<K,V> keyedPool, K key, int minIdle, long period) throws IllegalArgumentException
Periodically check the idle object count for the key in the keyedPool. At most one idle object will be added per period. If there is an exception when callingKeyedObjectPool.addObject(Object)then no more checks for that key will be performed.- Type Parameters:
K- the type of the pool keyV- the type of pool entries- Parameters:
keyedPool- the keyedPool to check periodically.key- the key to check the idle count of.minIdle- if theKeyedObjectPool.getNumIdle(Object)is less than this then add an idle object.period- the frequency to check the number of idle objects in a keyedPool, seeTimer.schedule(TimerTask, long, long).- Returns:
- the
TimerTaskthat will periodically check the pools idle object count. - Throws:
IllegalArgumentException- whenkeyedPool,keyisnullor whenminIdleis negative or whenperiodisn't valid forTimer.schedule(TimerTask, long, long).
-
checkMinIdle
public static <K,V> Map<K,TimerTask> checkMinIdle(KeyedObjectPool<K,V> keyedPool, Collection<K> keys, int minIdle, long period) throws IllegalArgumentException
Periodically check the idle object count for each key in theCollection keysin the keyedPool. At most one idle object will be added per period.- Type Parameters:
K- the type of the pool keyV- the type of pool entries- Parameters:
keyedPool- the keyedPool to check periodically.keys- a collection of keys to check the idle object count.minIdle- if theKeyedObjectPool.getNumIdle(Object)is less than this then add an idle object.period- the frequency to check the number of idle objects in a keyedPool, seeTimer.schedule(TimerTask, long, long).- Returns:
- a
Mapof key andTimerTaskpairs that will periodically check the pools idle object count. - Throws:
IllegalArgumentException- whenkeyedPool,keys, or any of the values in the collection isnullor whenminIdleis negative or whenperiodisn't valid forTimer.schedule(TimerTask, long, long).- See Also:
checkMinIdle(KeyedObjectPool, Object, int, long)
-
prefill
@Deprecated public static <T> void prefill(ObjectPool<T> pool, int count) throws Exception, IllegalArgumentException
Deprecated.- Type Parameters:
T- the type of objects in the pool- Parameters:
pool- the pool to prefill.count- the number of idle objects to add.- Throws:
Exception- whenObjectPool.addObject()fails.IllegalArgumentException- whenpoolisnull.
-
prefill
@Deprecated public static <K,V> void prefill(KeyedObjectPool<K,V> keyedPool, K key, int count) throws Exception, IllegalArgumentException
Deprecated.- Type Parameters:
K- the type of the pool keyV- the type of pool entries- Parameters:
keyedPool- the keyedPool to prefill.key- the key to add objects for.count- the number of idle objects to add forkey.- Throws:
Exception- whenKeyedObjectPool.addObject(Object)fails.IllegalArgumentException- whenkeyedPoolorkeyisnull.
-
prefill
@Deprecated public static <K,V> void prefill(KeyedObjectPool<K,V> keyedPool, Collection<K> keys, int count) throws Exception, IllegalArgumentException
Deprecated.CallsKeyedObjectPool.addObject(Object)onkeyedPoolwith each key inkeysforcountnumber of times. This has the same effect as callingprefill(KeyedObjectPool, Object, int)for each key in thekeyscollection.- Type Parameters:
K- the type of the pool keyV- the type of pool entries- Parameters:
keyedPool- the keyedPool to prefill.keys-Collectionof keys to add objects for.count- the number of idle objects to add for eachkey.- Throws:
Exception- whenKeyedObjectPool.addObject(Object)fails.IllegalArgumentException- whenkeyedPool,keys, or any value inkeysisnull.- See Also:
prefill(KeyedObjectPool, Object, int)
-
synchronizedPooledFactory
public static <T> PooledObjectFactory<T> synchronizedPooledFactory(PooledObjectFactory<T> factory)
Returns a synchronized (thread-safe) PooledObjectFactory backed by the specified PooledObjectFactory.- Type Parameters:
T- the type of objects in the pool- Parameters:
factory- the PooledObjectFactory to be "wrapped" in a synchronized PooledObjectFactory.- Returns:
- a synchronized view of the specified PooledObjectFactory.
-
synchronizedKeyedPooledFactory
public static <K,V> KeyedPooledObjectFactory<K,V> synchronizedKeyedPooledFactory(KeyedPooledObjectFactory<K,V> keyedFactory)
Returns a synchronized (thread-safe) KeyedPooledObjectFactory backed by the specified KeyedPoolableObjectFactory.- Type Parameters:
K- the type of the pool keyV- the type of pool entries- Parameters:
keyedFactory- the KeyedPooledObjectFactory to be "wrapped" in a synchronized KeyedPooledObjectFactory.- Returns:
- a synchronized view of the specified KeyedPooledObjectFactory.
-
-