public class Pool<T>
extends java.lang.Object
push(Object)
. This is the only situation in which that method
may be called.
To simply fill the pool without a corresponding pop(), the add() method
must be used. This method will attempt to aquire a permit to add to the pool.Modifier and Type | Class and Description |
---|---|
static class |
Pool.Builder<T> |
class |
Pool.Entry |
static class |
Pool.Event |
static class |
Pool.HardReference<T> |
static interface |
Pool.Supplier<T> |
Constructor and Description |
---|
Pool(int max,
int min,
boolean strict) |
Pool(int max,
int min,
boolean strict,
long maxAge,
long idleTimeout,
long sweepInterval,
java.util.concurrent.Executor executor,
Pool.Supplier<T> supplier,
boolean replaceAged,
double maxAgeOffset,
boolean garbageCollection,
boolean replaceFlushed) |
Modifier and Type | Method and Description |
---|---|
boolean |
add(T obj)
Attempt to aquire a permit to add the object to the pool.
|
boolean |
add(T obj,
long offset)
Attempt to aquire a permit to add the object to the pool.
|
boolean |
close(long timeout,
java.util.concurrent.TimeUnit unit) |
void |
discard()
Used when a call to pop() was made that returned null
indicating that the caller has a permit to create an
object for this pool, but the caller will not be exercising
that permit and wishes intstead to return "null" to the pool.
|
void |
discard(Pool.Entry entry) |
void |
flush() |
Pool.Entry |
pop(long timeout,
java.util.concurrent.TimeUnit unit)
Any successful pop() call requires a corresponding push() or discard() call
A pop() call that returns null is considered successful.
|
boolean |
push(Pool.Entry entry) |
boolean |
push(T obj)
Never call this method without having successfully called
pop(long, TimeUnit) beforehand. |
boolean |
running() |
Pool |
start() |
void |
stop() |
public Pool(int max, int min, boolean strict)
public Pool(int max, int min, boolean strict, long maxAge, long idleTimeout, long sweepInterval, java.util.concurrent.Executor executor, Pool.Supplier<T> supplier, boolean replaceAged, double maxAgeOffset, boolean garbageCollection, boolean replaceFlushed)
public Pool start()
public void stop()
public boolean running()
public void flush()
public Pool.Entry pop(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException, java.util.concurrent.TimeoutException
timeout
- time to block while waiting for an instanceunit
- unit of time dicated by the timeoutjava.lang.InterruptedException
- vm level thread interruptionjava.lang.IllegalStateException
- if a permit could not be acquiredjava.util.concurrent.TimeoutException
- if no instance could be obtained within the timeoutpublic boolean add(T obj)
obj
- object to add to the poolpublic boolean add(T obj, long offset)
obj
- object to add to the pooloffset
- creation time offset, used for maxAgepublic boolean push(T obj)
pop(long, TimeUnit)
beforehand.
Failure to do so will increase the max pool size by one.obj
- object to push onto the poolpublic boolean push(Pool.Entry entry)
public void discard()
public void discard(Pool.Entry entry)
public boolean close(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
java.lang.InterruptedException