|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectnet.sf.mmm.util.pool.base.AbstractPool<E>
E - is the generic type of the pooled elements.public abstract class AbstractPool<E>
This is the abstract base implementation of the Pool interface.
| Field Summary | |
|---|---|
static int |
DEFAULT_CAPACITY
The default capacity used. |
| Constructor Summary | |
|---|---|
AbstractPool()
The constructor. |
|
AbstractPool(int capacity,
boolean threadsafe)
The constructor. |
|
AbstractPool(int capacity,
Object lock)
The constructor for a thread-safe pool with an externally given lock for synchronization. |
|
| Method Summary | |
|---|---|
E |
borrow()
This method borrows an element from this pool. |
void |
clear()
This method clears the complete pool. |
protected abstract E |
create()
This method creates a new element. |
int |
getCapacity()
This method gets the capacity of this pool. |
int |
getSize()
This method gets the size of the pool. |
boolean |
isEmpty()
This method determines if the pool is empty. |
void |
release(E element)
This method releases the given element. |
protected boolean |
reset(E element)
This method resets the given element so it can be reused. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int DEFAULT_CAPACITY
| Constructor Detail |
|---|
public AbstractPool()
<E>).
public AbstractPool(int capacity,
boolean threadsafe)
capacity - is the capacity.threadsafe - if true the pool needs to be accessed by
multiple Threads concurrently, false
otherwise.
public AbstractPool(int capacity,
Object lock)
lock for synchronization.
capacity - is the capacity.lock - is an object used for synchronization.| Method Detail |
|---|
public E borrow()
release it.empty, a new instance is created for
you. Otherwise a existing instance (that has been
released before) will be returned so it can be
reused.
borrow in interface Pool<E>null. This may only happen if explicitly documented
by the chosen implementation.protected abstract E create()
protected boolean reset(E element)
element so it can be reused. It
is called if an element is released and will be
stored in the pool. The implementation depends on the type of element. Some
types may become inconsistent if they are directly reused. Further this
method may clear data from the element for security reasons, because the
same instance may be given to some other component that is NOT trusted
enough (because it may be vulnerably).
element - the element to reset.
true if the given element can be
reused and should be added to the pool, false
otherwise.public boolean isEmpty()
isEmpty in interface Pool<E>true if the pool is empty.Collection.isEmpty()public int getSize()
public int getCapacity()
size of this pool. If that size is reached further
released objects are NOT pooled and can be freed
by the garbage-collector.Pool depends heavily on the type of
objects that are pooled. For some lightweight objects a very high capacity
may suite. However for big buffers (e.g. char[65536]) the
capacity should be very low because otherwise your heap might get crowded.
public void release(E element)
element. It will be put back
into the pool.element
is NOT in use anymore. Therefore no reference should exist on the
element and you should NOT have passed the
element to a third-party library that may keep it in some
cache.
release in interface Pool<E>element - is the element to add to the pool.Collection.add(Object)public void clear()
empty.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||