在我的prod服务器上获得以下异常,但几小时后它会自动解析。这个问题可能是什么原因
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was234747 milliseconds ago.The last packet sent successfully to the server was 234747 milliseconds ago, which is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.
我们已经设置了autoReconnect = true,从论坛我发现我们需要启用空闲连接测试。请指教
应用程序中的任何未关闭的连接是否会导致此异常?
我们使用Ibatis,下面是Ibatisconfig文件
<transactionManager type="JDBC" commitRequired="true">
<dataSource type="SIMPLE">
<property name="JDBC.Driver" value="com.mysql.jdbc.Driver" />
<property name="JDBC.ConnectionURL"
value="<URL>?autoReconnect=true" />
<property name="JDBC.Username" value="<username>" />
<property name="JDBC.Password" value="<password>" />
<property name="JDBC.DefaultAutoCommit" value="false" />
<property name="Pool.TimeToWait" value="100" />
<property name="Pool.PingQuery" value="select 1" />
<property name="Pool.PingEnabled" value="true" />
<property name="Pool.PingConnectionsOlderThan" value="300000" />
<property name="Pool.PingConnectionsNotUsedFor" value="300000" />
</dataSource>
</transactionManager>
答案 0 :(得分:1)
嗯,在我的项目中我遇到了同样的问题。我们使用mysql,如果连接空闲8小时,那么db就不可用了。我们使用的解决方案是使用C3P0连接池。在这里检查一下。 http://www.mchange.com/projects/c3p0/