goldman
Class Pool<T>
java.lang.Object
goldman.Pool<T>
public abstract class Pool<T>
- extends Object
The abstract Pool class provides a way to reuse object to reduce
the overhead of performing garbage collection by supporting a reusable pool
of objects.
Constructor Summary |
Pool()
|
Method Summary |
T |
allocate()
Returns an available object from the pool, or creates one if the pool is empty. |
protected abstract T |
create()
|
void |
release(T x)
Moves the given object to the pool of available objects for
reuse. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Pool
public Pool()
allocate
public T allocate()
- Returns an available object from the pool, or creates one if the pool is empty.
release
public void release(T x)
- Moves the given object to the pool of available objects for
reuse.
- Parameters:
x
- an object that is no longer needed
REQUIRES:
the user does not retain a reference to the object released
create
protected abstract T create()
- Returns:
- a newly allocated object of type T