public class FairObjectPool extends TimedEntry implements java.lang.Runnable
| Modifier and Type | Class and Description |
|---|---|
static interface |
FairObjectPool.InstanceCreator |
| Constructor and Description |
|---|
FairObjectPool(FairObjectPool.InstanceCreator creator)
Creates a new pool with no limit on the maximum number of pooled objects and an initial pool size of
10. |
FairObjectPool(FairObjectPool.InstanceCreator creator,
int initialSize)
Creates a new pool with no limit on the maximum number of pooled objects and the specified initial pool size.
|
FairObjectPool(FairObjectPool.InstanceCreator creator,
int initialSize,
int maxSize)
Creates a new pool with a maximum total number of pooled objects of
maxSize. |
| Modifier and Type | Method and Description |
|---|---|
java.lang.Object |
acquire()
Gives out an instance produced by the
InstanceCreator. |
java.lang.Object |
acuireInternal() |
void |
dispose() |
void |
release(java.lang.Object o)
returns the object to the pool.
|
void |
run() |
protected void |
timedOut()
Runs what should be done at time out.
|
isDisabled, toStringpublic FairObjectPool(FairObjectPool.InstanceCreator creator)
10.creator - the instance creator for creating new pooled objectspublic FairObjectPool(FairObjectPool.InstanceCreator creator, int initialSize)
creator - the instance creator for creating new pooled objectspublic FairObjectPool(FairObjectPool.InstanceCreator creator, int initialSize, int maxSize)
maxSize. The pool will initially
have a capacity of initialSize instances. New instances will be created by the specified
creator.creator - the instance creator for creating new pooled objectsinitialSize - the initial pool sizemaxSize - the maximum pool size; if -1, no limit on the pool size is imposedpublic java.lang.Object acquire()
InstanceCreator. If a max size is set, this method will block
if the maximum number of object has been acquired. It will return with a new acquired object. The order in witch
two calls of acquire from two separate threads will return is FIFO. Specifically the first thing that happens as
soon as this method is invoked is to save the System.currentTimeMillis(). This value is used to
ensure FIFO order.InstanceCreator.public java.lang.Object acuireInternal()
public void release(java.lang.Object o)
protected void timedOut()
TimedEntrytimedOut in class TimedEntrypublic void dispose()
public void run()
run in interface java.lang.Runnable