Java – MySQL does not reconnect with JNDI Tomcat 6

I am using JNDI and Tomcat6 to manage my MySQL connection, my Catalina / domain com / ROOT. XML includes:

<Resource name="jdbc/db" auth="Container" type="javax.sql.DataSource"
   username="db1" password="somepass" driverClassName="com.MysqL.jdbc.Driver"             
   url="jdbc:MysqL://localhost:3306/db?autoReconnect=true" maxActive="15" maxIdle="3"  
   maxWait="5000" removeAbandoned="true" removeAbandonedTimeout="20" />

Although autoreconnect will reconnect to the database, it does not. After about 8 hours of inactivity, my application spits out the missing database connection error Any ideas?

Thank you, Fedor

Solution

Do not use autoreconnect It has a problem with it's been deprecated For example, when a thread uses a connection, you may have a disconnect / reconnect event Before passing them to the application, I will connect the test connection with testonmirror Here is an example:

<Resource name="jdbc/db"
          auth="Container"
          type="javax.sql.DataSource"
          username="db1"
          password="somepass"
          driverClassName="com.MysqL.jdbc.Driver"
          url="jdbc:MysqL://localhost:3306/db"
          maxActive="15"
          maxIdle="3"
          maxWait="5000"
          removeAbandoned="true"
          removeAbandonedTimeout="20"
          logAbandoned="true"
          factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory"
          validationQuery="select 1"
          minevictableIdleTimeMillis="3600000"
          timeBetweenEvictionRunsMillis="1800000"
          numTestsPerEvictionRun="10"
          testWhileIdle="true"
          testOnBorrow="true"
          testOnReturn="false"
          />
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>