You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Joachim Schuler <jo...@epecon.de> on 2003/06/19 15:31:49 UTC

[DBCP] Problems with SQLWarnings chained to Connections in the pool

Hi all,

we have recently migrated a web application from using poolman to dbcp. The
db driver used for this application is jconnect.

During some long-term tests, we observed a memory-leak like behaviour,
caused by a growing number of objects on the heap which could not be garbage
collected. After some investigation we found out that the memory is consumed
by SQLWarnings, chained to connections in the pool. The SQLWarnings are
generated when calling setReadOnly() on the underlying Connection (which is
done regularly when taking an object from the pool), and they never get
cleared.

We feel the application should not have to worry about that, but instead the
pool should provide a Connection without any "old" SQLWarnings attached to
it. We have therefore introduced a patch into DBCP. A modified version of
PoolableConnectionFactory.passivateObject(Object obj) that is clearing the
old SQLWarnings when returning a connection to the pool might look like
this:

public void passivateObject(Object obj) throws Exception {
    if(obj instanceof Connection) {
        Connection conn = (Connection)obj;
        if(!conn.getAutoCommit()) {
            conn.rollback();
        }
        try {
            conn.clearWarnings();
        } catch(Exception e) {}
    }

    if(obj instanceof DelegatingConnection) {
        ((DelegatingConnection)obj).passivate();
    }
}

We would be glad to see this or a similar solution incorporated into the
DBCP source tree.

Best regards,
- Joachim



Joachim Schuler, epecon GmbH, Ost-West-Strasse 63, D-20147 Hamburg
Tel. +49 40 300 697-38, Mobil: +49 171 875 8020, Fax +49 40 300 697 31
http://www.epecon.de


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