Mysql没有与JNDI Tomcat 6重新连接 [英] Mysql not reconnecting with JNDI Tomcat 6
问题描述
我正在使用JNDI和Tomcat6来管理Mysql连接,我的Catalina / domain.com / ROOT.xml有:
I am using JNDI with Tomcat6 to manage Mysql connections, my Catalina/domain.com/ROOT.xml has:
<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" />
我虽然autoReconnect会重新连接到数据库,但是在大约8小时不活动后它没有我的应用程序吐出丢失的数据库错误连接。有什么想法?
I though autoReconnect will do the job reconnecting to database but it does not, after about 8 hours of inactivity my app spits out lost connection to database errors. Any ideas?
谢谢,Fedor
推荐答案
不要使用 autoReconnect的
。它有问题,并且它已被弃用。例如,当线程使用连接时,您可能会发生断开连接/重新连接事件。在将它们传递给应用程序之前,我会将您的连接池测试连接与 testOnBorrow
连接起来。以下是一个示例:
Dont use autoReconnect
. There are problems with it and it's been deprecated. For example, you could have a disconnect/reconnect event happen while a thread is using the connection. I would instead have your connection pool test connections with testOnBorrow
before passing them to the app. 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"
/>
这篇关于Mysql没有与JNDI Tomcat 6重新连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!