@wenshao 你好,想跟你请教个问题:
因为测试环境tomcat和mysql不在同一台服务器上,有时会出现网络通迅丢包或者短时间断网的问题。对此做了如下配置:
<property name="validationQuery" value="SELECT 1" />
<property name="testOnBorrow" value="true" />
<property name="testOnReturn" value="true" />
<property name="testWhileIdle" value="true" />
但是依然会出现链接失效的错误:
……
Couldn't rollback jdbc connection. No operations allowed after connection closed.
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed.
……
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet successfully received from the server was 32,542 milliseconds ago. The last packet sent successfully to the server was 18,903 milliseconds ago.
……
Caused by: java.net.SocketTimeoutException: Read timed out
而且错误会一直持续(除非重启tomcat),好像testOnBorrow, testWhileIdle, testWhileIdle并没有起效。
hibernate报出的异常:
引用来自“ddatsh”的评论
加timeBetweenEvictionRunsMillis这个有加:
<!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 --><property name="timeBetweenEvictionRunsMillis" value="60000" />
<!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
<property name="minEvictableIdleTimeMillis" value="25200000" />
刚看了些贴子
这个问题叫:数据库链接池断网重连比较科学。