commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sandy McArthur <>
Subject Re: Requirements for Commons Pool
Date Fri, 10 Feb 2006 21:23:13 GMT
On 2/10/06, starki78 <> wrote:
> Is there the possibility to use the pool
> with these two options:
> String key = POOL.putObject(Object o) {}
> POOL.putObject(Object o,String key) {}
> The crucial point is that a unique key is created internally and given back
> to the user.

No. You need to come up with your own keys. An easy way is to simply
create one with:

Object key = new Object();

Though Object may not have the equals() and hashCode() behaviors you
really want so many people use Strings. You're on your own when it
comes to creating a unique String token.

KeyedObjectPools usualy create objects on demand, you simply ask for
an object with a key. eg:

Object obj1 = pool.borrowObject(key);
Object obj2 = pool.borrowObject(key);

but don't forget to return a borrowed object with:

pool.returnObject(key, obj1);
pool.returnObject(key, obj2);

> Another requirement is that the pool elements can be deleted after a timeout
> (e.g. after one our)

To expire stale objects you need to request that behavior when you
create the KeyedObjectPool:

KeyedPoolableObjectFactory kpof = new MyKeyedPoolableObjectFactory();
GenericKeyedObjectPool.Config config = new GenericKeyedObjectPool.Config();
config.timeBetweenEvictionRunsMillis = 10 * 60 * 1000; // check every 10 minutes
config.minEvictableIdleTimeMillis = 60 * 60 * 1000; // evict objects
idle for an hour
KeyedObjectPool pool = GenericKeyedObjectPool(kpof, config);

To use Commons Pool correctly you really need to make your own
[Keyed]PoolableObjectFactory implementations. Some [Keyed]ObjectPool
implementations may work without them but doing so basicly criples the
effictiveness of the commons pool.

See the examples at or read the
JavaDocs: .

Sandy McArthur

"He who dares not offend cannot be honest."
- Thomas Paine

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message