public class SimplePool<T> extends Object implements Pool<T>
Pool
supporting dynamic resizing and a variable
timeout when attempting to obtain an item from the pool. Pool grows on
demand up to the limit.Modifier and Type | Class and Description |
---|---|
static interface |
SimplePool.PoolItemCallback<T>
User of the pool provide an implementation of this interface; called during
various pool operations.
|
Constructor and Description |
---|
SimplePool(int poolSize,
SimplePool.PoolItemCallback<T> callback)
Creates a SimplePool with a specific limit.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Close the pool; returned items will be destroyed.
|
int |
getActiveCount()
Returns the number of allocated items that are currently
checked out of the pool.
|
int |
getAllocatedCount()
Returns the current count of allocated items (in use and
idle).
|
int |
getIdleCount()
Returns the number of items that have been allocated
but are not currently in use.
|
T |
getItem()
Obtains an item from the pool; waits up to waitTime milliseconds (default infinity).
|
int |
getPoolSize()
Returns the current size of the pool; may be greater than the target pool size
if it was recently reduced and too many items were in use to allow the new size
to be set.
|
void |
releaseItem(T item)
Returns an item to the pool.
|
void |
removeAllIdleItems()
Removes all idle items from the pool.
|
void |
setPoolSize(int poolSize)
Adjusts the current pool size.
|
void |
setWaitTimeout(long waitTimeout)
Adjusts the wait timeout - the time for which getItem() will wait if no idle
entries are available.
|
protected final Log logger
public SimplePool(int poolSize, SimplePool.PoolItemCallback<T> callback)
poolSize
- The maximum number of items the pool supports.callback
- A SimplePool.PoolItemCallback
implementation called during various
pool operations.public void setPoolSize(int poolSize)
poolSize
- The desired target pool size.public int getPoolSize()
getPoolSize
in interface Pool<T>
public int getIdleCount()
Pool
getIdleCount
in interface Pool<T>
public int getActiveCount()
Pool
getActiveCount
in interface Pool<T>
public int getAllocatedCount()
Pool
getAllocatedCount
in interface Pool<T>
public void setWaitTimeout(long waitTimeout)
waitTimeout
- The wait timeout in milliseconds.public T getItem()
getItem
in interface Pool<T>
PoolItemNotAvailableException
- if no items become available in time.public void releaseItem(T item)
releaseItem
in interface Pool<T>
item
- the item.public void removeAllIdleItems()
Pool
removeAllIdleItems
in interface Pool<T>