Mysql not reconnecting with JNDI Tomcat 6

最后都变了- 提交于 2019-12-02 21:20:45

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"
          />
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!