Modifier and Type | Class and Description |
---|---|
static interface |
ConcurrentPool.ItemFactory<T>
Factory for creating and closing pooled items.
|
Modifier and Type | Field and Description |
---|---|
private java.util.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(boolean initialize) |
void |
ensureMinSize(int minSize,
boolean initialize) |
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.Deque<T> available
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)
public void release(T t, boolean prune)
public T get()
public T get(long timeout, java.util.concurrent.TimeUnit timeUnit)
get
in interface Pool<T>
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, boolean initialize)
private T createNewAndReleasePermitIfFailure(boolean initialize)
protected boolean acquirePermit(long timeout, java.util.concurrent.TimeUnit timeUnit)
protected void releasePermit()
public int getMaxSize()
public int getInUseCount()
public int getAvailableCount()
public int getCount()
public java.lang.String toString()
toString
in class java.lang.Object
private void close(T t)