You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Glenn Nielsen <gl...@voyager.apg.more.net> on 2002/06/29 19:00:58 UTC

[DBCP] Connection.close() of already closed connections

When DBCP closes a db Connection the object is recyled back into
the pool and made available for reuse.  When being used inside
a threaded container like Tomcat it is possible for the following
to happen:

Thread for Request A gets a db connection
Thread for Request A does some work with the db
Thread for Request A closes the db connection
Thread for Request B gets a db connection
  (the same connection Request A just closed)
Due to a bug (most likely an Exception handling bug),
  Thread for Request A closes the db connection again
Thread for Request B tries to use the db connectin,
  Thread B gets an SQLException "Connection is closed."

Solution:

Which thread opened a db connection should be tracked.
DelegatingConnection.close() should then ignore the
close request if the currentThread is not the same
Thread which opened the connection.

A separate closeAbandoned() method would be available to allow the code
which removes abandoned connections to force closure of a connection
even though a different thread is requesting it.

Comments?

Regards,

Glenn

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>