I have a DBCP connection pool in Tomcat. The problem is that when the connection is lost briefly the appliction is broken because DBCP won't try to reconnect again later when there is a connection. Can I get DBCP to reconnect automatically?
A:
Would autoReconnect=true
do the job when added to the connection string?
jdbc:mysql://localhost:3306/appfuse?autoReconnect=true -> jdbc:db2:appfuse
Leniel Macaferi
2010-03-30 20:00:01
Is this only for MySQL?
wesley
2010-03-30 20:12:15
Yes, that's a mysql thing
nos
2010-03-30 20:15:06
Oh sorry, I saw the db2 after -> and thought this would work... didn't see the mysql... I won't delete this answer because someone may find this question looking for autoreconnect problem.
Leniel Macaferi
2010-03-30 20:34:42
+1
A:
There are 2 ways to "solve" this, though both have some issues:
You can use a "validationQuery" (see below) to have a test query run before you go (generally something like 'select 1 from dual' which will be used to test connections before/after you get/give them to the pool. This adds an extra call per connection request from the pool. See: http://wiki.apache.org/commons/DBCP
Instead of doing this per query, you can have the idleEvictorThread do it by setting testWhileIdle, though in some versions that thread can cause deadlocking under high-load. See: http://commons.apache.org/dbcp/configuration.html for more details on that and other options
jayshao
2010-03-31 23:00:37