即使使用 'autoReconnect=true' MySql JDBC 超时

标签 mysql jdbc timeout

<分区>

有时,我的 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 一次数据库服务器。我已将 autoReconnect 参数添加到打开的 URL,没有明显影响。

知道这里的问题是什么吗? 谢谢 帕特

最佳答案

您应该为网络故障编写代码并自行处理自动重新连接。

自动重新连接是故意关闭的,因为当连接断开并以不同状态返回时,会悄悄发生一些“应用程序”错误。

无论如何,评论表明这是一个重复的问题。

关于即使使用 'autoReconnect=true' MySql JDBC 超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9674165/

相关文章:

java - 在嵌套循环中使用准备好的语句的最佳方法

jdbc - Hive JDBC 客户端抛出 SQLException

ruby-on-rails - Rails ActiveRecord checkout_timeout 设置被忽略

php - 搜索引擎/分页

oracle - 使用 Apache Spark 1.4.0 写入 Oracle 数据库

mysql - SQL:搜索一列中给定的不允许的字符并替换

javascript - Angular 一 : javascript timeout function

postgresql - libpq Postgres PQexecParams 2 小时超时

php - 随机播放前 20 个准备好的语句结果

php - 输出数据到表中