Overview – Apache Commons Pool
Apache Commons Pool ™
Last Published: 30 Dec 2025
Version: 2.13.1
ApacheCon
Apache
Commons
Commons Pool
About
Asking Questions
Release History
Issue Tracking
Dependency Management
Javadoc
Javadoc Archive 2.x
Javadoc Archive 1.x
Sources
Security
License
Code of Conduct
Examples
Project Documentation
Project Information
About
Summary
Team
Source Code Management
Issue Management
Mailing Lists
Maven Coordinates
Dependency Management
Dependencies
Dependency Convergence
CI Management
Distribution Management
Project Reports
Commons
License
Components
Sandbox
Dormant
General Information
Security
Volunteering
Contributing Patches
Building Components
Commons Parent POM
Commons Build Plugin
Commons Release Plugin
Site Publication
Releasing Components
Wiki
ASF
How the ASF works
Get Involved
Developer Resources
Code of Conduct
Sponsorship
Thanks
Apache Commons Pool
The Apache Commons Pool open source software library provides
an object-pooling API and a number of object pool implementations.
Version 2 of Apache Commons Pool contains a completely re-written
pooling implementation compared to the 1.x series. In addition to
performance and scalability improvements, version 2 includes robust
instance tracking and pool monitoring.
Version 2.7.x and up requires Java 8 or above.
Version 2.6.x requires Java 7 or above.
Version 2.5.x requires Java 7 or above.
Version 2.0 requires 6 or above.
Releases
See the
downloads
page for information
on obtaining releases.
Features
The
org.apache.commons.pool2
package defines a handful of pooling interfaces and some base classes
that may be useful when creating new pool implementations.
PooledObjectFactory
PooledObjectFactory
provides a generic interface for managing the lifecycle of a pooled object:
public interface PooledObjectFactory
activateObject(PooledObject
destroyObject(PooledObject
destroyObject(PooledObject
makeObject()
passivateObject(PooledObject
validateObject(PooledObject
Users of 1.x versions of Commons Pool will notice that while the
PoolableObjectFactory
s used by
1.x pools create and manage pooled objects directly, version 2
PooledObjectFactory
s create and
manage
PooledObject
s. These object wrappers
maintain object pooling state, enabling
PooledObjectFactory
methods to have access to data such
as instance creation time or time of last use. A
DefaultPooledObject
is
provided, with natural implementations for pooling state methods. The simplest way to implement a
PoolableObjectFactory
is to have it extend
BasePooledObjectFactory
This factory provides a
makeObject()
that returns
wrap(create())
where
create
and
wrap
are abstract. You provide an implementation of
create
to create the underlying objects that you want to manage in the pool and
wrap
to wrap created
instances in
PooledObject
s. To use
DefaultPooledObject
wrappers, use
@Override
public PooledObject
return new DefaultPooledObject
where
Foo
is the type of the objects being pooled (the return type of
create()
).
KeyedPooledObjectFactory
defines a similar interface for
KeyedObjectPool
s:
public interface KeyedPooledObjectFactory
PooledObject
void activateObject(K key, PooledObject
void passivateObject(K key, PooledObject
boolean validateObject(K key, PooledObject
void destroyObject(K key, PooledObject
BaseKeyedPooledObjectFactory
provides an abstract base implementation of
KeyedPooledObjectFactory
The
org.apache.commons.pool2.impl
package provides some
Pool
implementations.
GenericObjectPool
GenericObjectPool
provides a wide variety of configuration options, including the ability to cap the number of idle or
active instances, to evict instances as they sit idle in the pool, etc. As of version 2,
GenericObjectPool
also provides abandoned instance tracking and removal.
GenericKeyedObjectPool
offers the same behavior for keyed pools.
SoftReferenceObjectPool
SoftReferenceObjectPool
can grow as needed, but allows the garbage collector to evict idle instances from the pool as needed.
Migrating from Pool 2.x to Pool 2.y
Client code that uses a Pool 2.x release should require no code
changes to work with a later Pool 2.x release.
New Pool 2.x releases may include support for new configuration
attributes. These will be listed in the change log. Note that the
MBean interfaces (those with names ending in MXBean or MBean) such as
DefaultPooledObjectInfoMBean
GenericKeyedObjectPoolMXBean
or
GenericKeyedObjectPoolMXBean
may change from one release to the next to support these new
attributes. These interfaces should, therefore, not be implemented by
client as the changes will not be backwards compatible.
Migrating from Pool 1.x to Pool 2.x
The migration from Apache Commons Pool 1.x to 2.x will require some
code changes. The most significant changes are the changes in package
name from
org.apache.commons.pool
to
org.apache.commons.pool2
and the change in the implementation
classes to use
PooledObjectFactory
s, as described above.
The key implementation classes (
GenericObjectPool
and
GenericKeyedObjectPool
) have retained their names so no
changes should be required there although a number of attributes have
been renamed to improve consistency and ensure attributes with the
same name in different pools have the same meaning. It is likely that
some changes will be required to use the new attribute names.
Copyright © 2001-2026
The Apache Software Foundation
Apache Commons, Apache Commons Pool, Apache, the Apache logo, and the Apache Commons project logos are trademarks of The Apache Software Foundation.
All other marks mentioned may be trademarks or registered trademarks of their respective owners.
US