【发布时间】:2012-03-12 20:17:40
【问题描述】:
有时,我的 Java/Tomcat6/Debian Squeeze 应用程序无法与 MySql 服务器通信。 Tomcat 应用程序位于前端服务器上,而 MySql 位于单独的仅 MySql 的盒子上。一个典型的错误是:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was56588 milliseconds ago.
The last packet sent successfully to the server was 56588 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.
给出的超时时间只有60秒,看起来很短。如果是一个小时或更长时间,我会简单地设置一个后台任务来每隔几分钟 ping 数据库服务器。我在打开的 URL 中添加了 autoReconnect 参数,没有明显的影响。
知道这里的问题是什么吗? 谢谢 帕特
【问题讨论】:
-
@tusar,感谢您的链接。解释了为什么我有很多代码要写。有趣的是他们正在弃用自动重新连接。
-
服务器上的 wait_timeout 设置为什么?