T - the poolable typepublic class ObjectPool<T extends Poolable<T>>
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
private int |
maxSize
Stores the maximum size of the pool.
|
private ArrayList<T> |
pool
Stores the pool.
|
private T |
prototype
Stores a prototype instance for creating instances.
|
| Constructor and Description |
|---|
ObjectPool(T prototype)
Creates a new unlimited pool.
|
ObjectPool(T prototype,
int maxSize)
Creates a new pool.
|
| Modifier and Type | Method and Description |
|---|---|
T |
getFromPool()
Returns an instance from the shared pool.
|
void |
release(T instance)
Releases and clears the specified instance
to the shared pool.
|
int |
size()
Returns the size of the pool.
|
private T extends Poolable<T> prototype
private int maxSize
public ObjectPool(T prototype)
prototype - the prototype instance for object creation (must not
be null)public ObjectPool(T prototype, int maxSize)
prototype - the prototype instance for object creation (must not
be null)maxSize - the maximum size of the poolpublic final T getFromPool()
release(Poolable).public final void release(T instance)
instance - the instance to be released (must not be null)public int size()