Package net.timewalker.ffmq4.utils.pool
Class ObjectPool<T>
- java.lang.Object
-
- net.timewalker.ffmq4.utils.pool.ObjectPool<T>
-
- All Implemented Interfaces:
ObjectPoolMBean
- Direct Known Subclasses:
AsyncTaskProcessorThreadPool
public abstract class ObjectPool<T> extends Object implements ObjectPoolMBean
ObjectPool
-
-
Field Summary
Fields Modifier and Type Field Description static intWHEN_EXHAUSTED_BLOCKstatic intWHEN_EXHAUSTED_FAILExhaustion policiesstatic intWHEN_EXHAUSTED_RETURN_NULLstatic intWHEN_EXHAUSTED_WAITstatic intWHEN_EXHAUSTED_WAIT_RETURN_NULL
-
Constructor Summary
Constructors Constructor Description ObjectPool(int minSize, int maxIdle, int maxSize, int exhaustionPolicy, long waitTimeout)Constructor
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Tborrow()Borrow an object from the poolvoidclose()Close the pool, destroying all objectsprotected abstract TcreatePoolObject()Create a new pool objectprotected abstract voiddestroyPoolObject(T poolObject)Destroy a pool objectstatic StringexhaustionPolicyAsString(int exhaustionPolicy)intgetThreadPoolAvailableCount()intgetThreadPoolExhaustionPolicy()intgetThreadPoolMaxIdle()intgetThreadPoolMaxSize()intgetThreadPoolMinSize()intgetThreadPoolPendingWaits()intgetThreadPoolSize()longgetThreadPoolWaitTimeout()protected voidinit()voidrelease(T poolObject)Return an object to the pool
-
-
-
Field Detail
-
WHEN_EXHAUSTED_FAIL
public static final int WHEN_EXHAUSTED_FAIL
Exhaustion policies- See Also:
- Constant Field Values
-
WHEN_EXHAUSTED_BLOCK
public static final int WHEN_EXHAUSTED_BLOCK
- See Also:
- Constant Field Values
-
WHEN_EXHAUSTED_WAIT
public static final int WHEN_EXHAUSTED_WAIT
- See Also:
- Constant Field Values
-
WHEN_EXHAUSTED_RETURN_NULL
public static final int WHEN_EXHAUSTED_RETURN_NULL
- See Also:
- Constant Field Values
-
WHEN_EXHAUSTED_WAIT_RETURN_NULL
public static final int WHEN_EXHAUSTED_WAIT_RETURN_NULL
- See Also:
- Constant Field Values
-
-
Method Detail
-
init
protected void init() throws javax.jms.JMSException- Throws:
javax.jms.JMSException
-
borrow
public T borrow() throws javax.jms.JMSException
Borrow an object from the pool- Returns:
- a pooled object
- Throws:
javax.jms.JMSException
-
release
public void release(T poolObject)
Return an object to the pool- Parameters:
poolObject- a pooled object to be returned
-
close
public void close()
Close the pool, destroying all objects
-
createPoolObject
protected abstract T createPoolObject() throws Exception
Create a new pool object- Returns:
- an new pool object
- Throws:
Exception- on creation error
-
destroyPoolObject
protected abstract void destroyPoolObject(T poolObject) throws Exception
Destroy a pool object- Parameters:
poolObject- the object to destroy- Throws:
Exception- on release error
-
getThreadPoolMaxIdle
public int getThreadPoolMaxIdle()
- Specified by:
getThreadPoolMaxIdlein interfaceObjectPoolMBean- Returns:
- the maxIdle
-
getThreadPoolMinSize
public int getThreadPoolMinSize()
- Specified by:
getThreadPoolMinSizein interfaceObjectPoolMBean- Returns:
- the minSize
-
getThreadPoolMaxSize
public int getThreadPoolMaxSize()
- Specified by:
getThreadPoolMaxSizein interfaceObjectPoolMBean- Returns:
- the maxSize
-
getThreadPoolExhaustionPolicy
public int getThreadPoolExhaustionPolicy()
- Specified by:
getThreadPoolExhaustionPolicyin interfaceObjectPoolMBean- Returns:
- the exhaustionPolicy
-
getThreadPoolWaitTimeout
public long getThreadPoolWaitTimeout()
- Specified by:
getThreadPoolWaitTimeoutin interfaceObjectPoolMBean- Returns:
- the waitTimeout
-
getThreadPoolAvailableCount
public int getThreadPoolAvailableCount()
- Specified by:
getThreadPoolAvailableCountin interfaceObjectPoolMBean- Returns:
- the available count
-
getThreadPoolPendingWaits
public int getThreadPoolPendingWaits()
- Specified by:
getThreadPoolPendingWaitsin interfaceObjectPoolMBean- Returns:
- the pendingWaits
-
getThreadPoolSize
public int getThreadPoolSize()
- Specified by:
getThreadPoolSizein interfaceObjectPoolMBean- Returns:
- the pool size
-
exhaustionPolicyAsString
public static String exhaustionPolicyAsString(int exhaustionPolicy)
-
-