net.sf.mmm.util.pool.api
Interface Pool<E>

Type Parameters:
E - is the templated type of the elements in the pool.
All Known Subinterfaces:
ByteArrayPool, CharArrayPool
All Known Implementing Classes:
AbstractNoPool, AbstractPool, ByteArrayPoolImpl, CharArrayPoolImpl, NoByteArrayPool, NoCharArrayPool

public interface Pool<E>

This is the interface for a simple pool. It allows to borrow an object from the pool. If that object is NOT needed anymore, it should be released.
A typical pool implementation will have an internal buffer to cache released objects so they can be reused for further requests. Such buffer should be limited to a maximum size (capacity). While that size is reached, released objects will NOT be cached anymore (and the garbage collector should free them).
ATTENTION:
Do NOT use this interface for a Thread-pool. There is already Executor for this use-case (see Executors).

Since:
1.0.0
Author:
Joerg Hohwiller (hohwille at users.sourceforge.net)

Method Summary
 E borrow()
          This method borrows an element from this pool.
 boolean isEmpty()
          This method determines if the pool is empty.
 void release(E element)
          This method releases the given element.
 

Method Detail

borrow

E borrow()
This method borrows an element from this pool. If you do NOT need the object anymore you should release it.
If this pool is 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.

Returns:
an element from the pool. Typically this method never returns null. This may only happen if explicitly documented by the chosen implementation.

release

void release(E element)
This method releases the given element. It will be put back into the pool.
ATTENTION:
Only call this method if you are sure that the given 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.

Parameters:
element - is the element to add to the pool.
See Also:
Collection.add(Object)

isEmpty

boolean isEmpty()
This method determines if the pool is empty.

Returns:
true if the pool is empty.
See Also:
Collection.isEmpty()


Copyright © 2001-2010 mmm-Team. All Rights Reserved.