You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by starki78 <st...@libero.it> on 2006/02/10 10:43:04 UTC

Requirements for Commons Pool

Hi!

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.

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

Is this already implemented in any way?

Nice greetings
Starky


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: Requirements for Commons Pool

Posted by Sandy McArthur <sa...@gmail.com>.
On 2/10/06, starki78 <st...@libero.it> 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
http://jakarta.apache.org/commons/pool/examples.html or read the
JavaDocs: http://jakarta.apache.org/commons/pool/apidocs/ .

--
Sandy McArthur

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

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org