commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Daniel Baldes">
Subject Re: [dbcp] connection events / connection close hook
Date Wed, 04 May 2011 12:51:03 GMT
On Tue, 03 May 2011 08:54:32 -0700 Phil Steitz <> 
> 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 


>> 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 
> 1) subclass BasicDataSource and override
> createPoolableConnectionFactory to use the subclassed factory from 
> 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,

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

View raw message