On Tue, 03 May 2011 08:54:32 -0700 Phil Steitz <[email protected]> wrote:
On 5/3/11 7:07 AM, Daniel Baldes wrote:
Hi,

I'd like to run some connection-specific clean-up code when a
physical database connection is closed by the connection pool.

You mean really closed, as in destroyed, or just returned to the pool?

Yes.


I found ConnectionEventListener and
PooledConnection.addConnectionEventListener() in the JDBC API,
however I think this is just used internally by JDBC drivers? At
least I found no reasonable way to attach my own listener to new
connections.

Right, these are not in general exposed.

Is there any way to do that with DBCP? (Or any other workable
connection pool implementation that you know?)

No direct way at least that I can think of.  If you are using DBCP
1.3+, you can may be able to get the behavior that you want by:

0) subclass PoolableConnectionFactory and override either
passivateObject (what is called when a connection is returned to the
pool) or destroyObject to do the cleanup (assuming you can make
available all of the references needed in the context of these methods)
1) subclass BasicDataSource and override
createPoolableConnectionFactory to use the subclassed factory from 0)

Sorry I can't see a simple way to do this.  Seems a reasonable
enhancement request.  Please feel free to open a JIRA.

Thanks for these hints. In the meantime, I found two database connection pools which seem to support this via listener interfaces: Proxool and BoneCP. The latter seems to be actually actively developed. Maybe you want to have a look at those if you plan to implement such an enhancement. I might open a JIRA, depending on the upcoming decision whether we will stick with DBCP.

Best regards,
Daniel

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to