class ConcurrentPool<T>
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
(package private) static interface |
ConcurrentPool.ItemFactory<T>
Factory for creating and closing pooled items.
|
| Modifier and Type | Field and Description |
|---|---|
private Deque<T> |
available |
private boolean |
closed |
private ConcurrentPool.ItemFactory<T> |
itemFactory |
private int |
maxSize |
private java.util.concurrent.Semaphore |
permits |
| Constructor and Description |
|---|
ConcurrentPool(int maxSize,
ConcurrentPool.ItemFactory<T> itemFactory)
Initializes a new pool of objects.
|
| Modifier and Type | Method and Description |
|---|---|
protected boolean |
acquirePermit(long timeout,
java.util.concurrent.TimeUnit timeUnit) |
void |
close()
Clears the pool of all objects.
|
private void |
close(T t) |
private T |
createNewAndReleasePermitIfFailure() |
void |
ensureMinSize(int minSize) |
T |
get()
Gets an object from the pool.
|
T |
get(long timeout,
java.util.concurrent.TimeUnit timeUnit)
Gets an object from the pool - will block if none are available
|
int |
getAvailableCount() |
int |
getCount() |
int |
getInUseCount() |
int |
getMaxSize() |
void |
prune() |
void |
release(T t)
Return an instance of T to the pool.
|
void |
release(T t,
boolean prune)
call done when you are done with an object from the pool if there is room and the object is ok will get added
|
protected void |
releasePermit() |
java.lang.String |
toString() |
private final int maxSize
private final ConcurrentPool.ItemFactory<T> itemFactory
private final java.util.concurrent.Semaphore permits
private volatile boolean closed
public ConcurrentPool(int maxSize,
ConcurrentPool.ItemFactory<T> itemFactory)
maxSize - max to hold to at any given time. if < 0 then no limititemFactory - factory used to create and close items in the poolpublic void release(T t)
release(t, false)t - item to return to the poolpublic void release(T t, boolean prune)
t - item to return to the poolprune - true if the item should be closed, false if it should be put back in the poolpublic T get()
public T get(long timeout, java.util.concurrent.TimeUnit timeUnit)
timeout - negative - forever 0 - return immediately no matter what positive ms to waittimeUnit - the time unit of the timeoutMongoTimeoutException - if the timeout has been exceededpublic void prune()
public void ensureMinSize(int minSize)
private T createNewAndReleasePermitIfFailure()
protected boolean acquirePermit(long timeout,
java.util.concurrent.TimeUnit timeUnit)
protected void releasePermit()
public void close()
public int getMaxSize()
public int getInUseCount()
public int getAvailableCount()
public int getCount()
public java.lang.String toString()
toString in class java.lang.Objectprivate void close(T t)