public abstract class Pool<T> extends Object
Modifier and Type | Class and Description |
---|---|
static interface |
Pool.Poolable
Objects implementing this interface will have
Pool.Poolable.reset() called when passed to free(Object) . |
Constructor and Description |
---|
Pool(boolean threadSafe,
boolean softReferences)
Creates a pool with no maximum.
|
Pool(boolean threadSafe,
boolean softReferences,
int maximumCapacity) |
Modifier and Type | Method and Description |
---|---|
void |
clean()
If using soft references, all soft references whose objects have been garbage collected are removed from the pool.
|
void |
clear()
Removes all free objects from this pool.
|
protected abstract T |
create() |
void |
free(T object)
Puts the specified object in the pool, making it eligible to be returned by
obtain() . |
int |
getFree()
The number of objects available to be obtained.
|
int |
getPeak()
The all-time highest number of free objects.
|
T |
obtain()
Returns an object from this pool.
|
protected void |
reset(T object)
Called when an object is freed to clear the state of the object for possible later reuse.
|
void |
resetPeak() |
public Pool(boolean threadSafe, boolean softReferences)
public Pool(boolean threadSafe, boolean softReferences, int maximumCapacity)
maximumCapacity
- The maximum number of free objects to store in this pool. Objects are not created until
obtain()
is called and no free objects are available.protected abstract T create()
public T obtain()
public void free(T object)
obtain()
. If the pool already contains
the maximum number of free objects, the specified object is reset but not added to the pool.
If using soft references and the pool contains the maximum number of free objects, the first soft reference whose object has been garbage collected is discarded to make room.
protected void reset(T object)
Pool.Poolable.reset()
if the object is Pool.Poolable
.public void clear()
public void clean()
getFree()
or when the pool has no maximum
capacity. It is not necessary to call clean()
before calling free(Object)
, which will try to remove an
empty reference if the maximum capacity has been reached.public int getFree()
If using soft references, this number may include objects that have been garbage collected. clean()
may be used
first to remove empty soft references.
public int getPeak()
resetPeak()
.
If using soft references, this number may include objects that have been garbage collected.
public void resetPeak()
Copyright © 2016–2021 Smart Data Analytics (SDA) Research Group. All rights reserved.