Reputation: 4121
I want to setup my tomcat datasources so that they recover the connections when a database goes down and comes back up. I am having trouble testing this at work (red tape etc)
Does anyone know if the following datasource setup in tomcat would recover itself?
<add:Resource auth="Container"
driverClassName="oracle.jdbc.OracleDriver"
initialSize="5"
logAbandoned="false"
maxActive="100"
maxWait="180000"
minEvictableIdleTimeMillis="240000"
minIdle="5"
name="jdbc/myDB"
password="${myDB.password}"
url="${myDB.url}"
username="${myDB.username}"
removeAbandoned="true"
removeAbandonedTimeout="60"
timeBetweenEvictionRunsMillis="10000"
type="javax.sql.DataSource"
validationQuery="select 1 from dual"
validationQueryTimeout="10"
validationInterval="10000"
testOnBorrow="true"
testWhileIdle="true"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory" />
Thanks Damien
Upvotes: 0
Views: 321
Reputation: 10828
I think just validationQuery
together with validationQueryTimeout
, which you already use, will do the job.
It is the most accurate way for tomcat to check the health of database connections associated to the pool objects.
Alternatively you can use validatorClassName
.
Note: you may wish to use lower values for: validationInterval
, validationQueryTimeout
, to recover faster from broken connections.
See all options here: https://tomcat.apache.org/tomcat-7.0-doc/jdbc-pool.html
Upvotes: 1