Jakarta Commons Object Pooling Package
Generic Object pooling API with several implementations.
Generic Object pooling API with several implementations.
The
org.apache.commons.pool
package defines a simple
interface for a pool of object instances, and a handful of base
classes that may be useful when creating pool implementations.
The api supports pooling of unique objects which can be requested
via a key as well as pools where all objects are equivalent.
The
org.apache.commons.pool.impl
package contains
several pool implementations.
StackObjectPool
is useful for supporting reuse of a limited number of instances while
allowing new instances to be created as needed to support high demand.
GenericObjectPool
has many configuration options and can support
a limited set of objects such as would be useful in a database
connection pool.
SoftReferenceObjectPool
has no limit on the number of objects in the
pool, but garbage collector can remove idle objects from the pool as
needed. There are also keyed versions of the first two.
Here is a simple example of pooling
HashMap
's. First
create an
ObjectPoolFactory
public class HashMapFactory
extends BasePoolableObjectFactory
{
/**
Creates an instance that can be returned by the pool.
Copyright © 2001-2003 Apache Software Foundation. Documenation generated March 31 2006.