Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tomcat need to restart after database restart

Tags:

java

mysql

tomcat

I have a webapp deployed in Tomcat 7. There I cave configured my database pool as given below.

<Resource name="UserDatabase" auth="Container"
          type="org.apache.catalina.UserDatabase"
          description="User database that can be updated and saved"
          factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
          pathname="conf/tomcat-users.xml" />

<Resource type="javax.sql.DataSource"
   name="jdbc/TEST"
   factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
   driverClassName="com.mysql.jdbc.Driver"
   url="jdbc:mysql://localhost:3306/testdb?zeroDateTimeBehavior=convertToNull"
   username="test"
   password="test"
   initialSize="10"
   maxActive="100"
   maxIdle="50"
   minIdle="10"/>

This configuration works fine.But I want to configure my database pool to reconnect data database server automatically when a database server down for sometime and started again.

like image 679
user1516815 Avatar asked Dec 08 '14 12:12

user1516815


2 Answers

Try to add

?autoReconnect=true

in your url.

like image 57
İlker Korkut Avatar answered Oct 27 '22 19:10

İlker Korkut


I found an answer for this problem. Below configuration done the job.

<Resource type="javax.sql.DataSource"
   name="jdbc/TEST"
   factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
   driverClassName="com.mysql.jdbc.Driver"
   url="jdbc:mysql://localhost:3306/testdb?zeroDateTimeBehavior=convertToNull"
   validationQuery="select 1"
   validationInterval="30000"
   testWhileIdle="true"
   testOnBorrow="true"
   testOnReturn="false"
   username="test"
   password="test"
   initialSize="10"
   maxActive="100"
   maxIdle="50"
   minIdle="10"/>
like image 32
user1516815 Avatar answered Oct 27 '22 18:10

user1516815