You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by "Leber, Dieter" <DI...@NDSatcom.com> on 2004/08/11 17:00:33 UTC

[DBCP] Question to database reconnection

I'm using DBCP 1.2 without using any validation of the connections 
(testOnBorrow = false, testOnReturn = false, timeBetweenEvictionRunsMillis = -1). 

When shutting down the database during running the application, the 
request using a pooled connection realizes that the database is down. 
Returning the connection to the pool seems to clean the pool (i.e. the 
pool has no active nor idle connections any longer). 

Starting the database again and demanding a connection from the 
pool a new connection is returned which has never been in the pool before.

If this is right no reconnection handling is needed at all because we always
have valid connections every time the database was down and started up again.

Can anyone please throw any light on this behaviour!? Are there 
situations where the pool is not cleaned so that validation is actually 
needed?

Dieter Leber

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


Re: [DBCP] Question to database reconnection

Posted by Dirk Verbeeck <di...@pandora.be>.
During the connection activation (when borrowing a connection) the 
setAutoCommit and other connection init methods are called.
If one of these methods throws a SQLException then the connection is 
also considered broken and removed from the pool.

So if you are using one of the "default*" properties and the JDBC 
driver correctly reports the SQLExceptions on the "set*" methods then 
you don't need an extra validationQuery.

Can you post the database+driver+config you are using?
Or even better, make a FAQ item of this in the DBCP wiki.

-- Dirk

Leber, Dieter wrote:
> I'm using DBCP 1.2 without using any validation of the connections 
> (testOnBorrow = false, testOnReturn = false, timeBetweenEvictionRunsMillis = -1). 
> 
> When shutting down the database during running the application, the 
> request using a pooled connection realizes that the database is down. 
> Returning the connection to the pool seems to clean the pool (i.e. the 
> pool has no active nor idle connections any longer). 
> 
> Starting the database again and demanding a connection from the 
> pool a new connection is returned which has never been in the pool before.
> 
> If this is right no reconnection handling is needed at all because we always
> have valid connections every time the database was down and started up again.
> 
> Can anyone please throw any light on this behaviour!? Are there 
> situations where the pool is not cleaned so that validation is actually 
> needed?
> 
> Dieter Leber



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


Re: [DBCP] Question to database reconnection

Posted by Craig McClanahan <cr...@gmail.com>.
On Wed, 11 Aug 2004 17:00:33 +0200, Leber, Dieter
<di...@ndsatcom.com> wrote:
> I'm using DBCP 1.2 without using any validation of the connections
> (testOnBorrow = false, testOnReturn = false, timeBetweenEvictionRunsMillis = -1).
> 
> When shutting down the database during running the application, the
> request using a pooled connection realizes that the database is down.
> Returning the connection to the pool seems to clean the pool (i.e. the
> pool has no active nor idle connections any longer).
> 
> Starting the database again and demanding a connection from the
> pool a new connection is returned which has never been in the pool before.
> 
> If this is right no reconnection handling is needed at all because we always
> have valid connections every time the database was down and started up again.
> 
> Can anyone please throw any light on this behaviour!? Are there
> situations where the pool is not cleaned so that validation is actually
> needed?

If the JDBC driver for your database does the transparent reconnect
thing (inside a Connection) for you, then there would not be a need to
have your connection pool do it.  My experience is that such a JDBC
driver is a rare animal.

The other thing that test-on-borrow helps you with, besides database
server restarts, is a connection that has been alive but idle for
longer than some timeout value built in to the database.  I've seen
this happen, for example, on Oracle databases with lightly used
applications (such as overnight) ... even though the database was not
shut down, the connections got stale.  Without a testOnBorrow
validation, my applications would have to deal with the resulting
SQLExceptions.  With testOnBorrow, the connection pool takes care of
it for me.

> 
> Dieter Leber
> 

Craig

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