Base class for a pool system implementation.
This class provides all the base functionality required and can be easily
extended to provide pooling support for many different types of object.
New objects are retrieved on demand according to specified limits,
and the pool can also ensure an object's validity before returning it.
The limits which can be set for a pool include the number of items to be
held in the pool, and the maximum number to ever be created.
The pool will try to maintain poolSize items open and ready
for use (unless that number has not yet been created), but if expiry is
enabled this number will reduce if the items are not used frequently.
If maxSize is specified then the pool will never create more
than this number of items, and another can only be obtained from the pool
if it is handed back by another client.
ObjectPool should be sub-classed to override
the following methods:
protected Reusable create() throws Exception
protected boolean isValid(final Reusable o)
protected void destroy(final Reusable o)
It is recommended that the sub-class implements methods for obtaining
and returning items within the pool, casting the objects returned by this
class as required to the appropriate class type.
ObjectPool also support asynchronous destruction of items, which can be
useful in circumstances where destruction of items held can take a long
time which would delay the checkIn method. |