commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Carman" <>
Subject RE: [Pool] force client to return the borrowed object to the pool
Date Fri, 24 Jun 2005 11:02:18 GMT
If the objects in the pool implement some sort of interface which your
client uses, you could make them return themselves to the pool.  All you
would have to do is wrap them with a proxy (as suggested below) which
implements the "client interface", but make the proxy timeout after a bit of
time, returning the wrapped object to the pool for others to use (if it
hasn't been returned already).  If the client tries to use the proxy object
after it has timed out, a RuntimeException could be thrown.  Though, the
current architecture doesn't allow you to wrap the actual pooled object.  It
returns the pooled object as-is.  But, you would need to be able to create a
new proxy each time an object is borrowed.  That might be a neat addition to
the framework.  
-----Original Message-----
From: Dirk Verbeeck [] 
Sent: Friday, June 24, 2005 1:51 AM
To: Jakarta Commons Developers List
Subject: Re: [Pool] force client to return the borrowed object to the pool


The technique you propose can already be seen in DBCP.
The real database connections are wrapped with a "poolable" delegating 
wrapper. The close method has been overwritten to call returnObject.

But an example inside commons-pool would be nice. In the wiki or on the 
Maybe some general code could be written to support this pattern.
Using reflexion/java proxy or even bytecode manipulation you could 
implement the "forced" return of the object.

The challenge is of course to find an elegant implementation that 
doesn't add too much complexity.


Edin Ahmetagic wrote:
> Hello,
> could there be an architectual solution to force the clients, that borrows
> objects from the pool, to return this back?
> An approach coud be, to have an Interface "PoolableObject" which have to
> implemented by the Objects that want to be pooled. In this Interface there
> could be an methode returnObject.
> I`am not sure if this is really possible, it is only an idea.
> Edin
> --

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

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

View raw message