jdbc4 CommunicationsException

我有一台运行java应用程序的机器与在同一实例上运行的mysql实例交谈。 该应用程序使用mysql的jdbc4驱动程序。 我随机时间不断收到com.mysql.jdbc.exceptions.jdbc4.CommunicationsException。

这是整个信息。

无法打开JDBC Connection进行事务处理; 嵌套exception是

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was25899 milliseconds ago.The last packet sent successfully to the server was 25899 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. 

对于mysql,全局’wait_timeout’和’interactive_timeout’的值设置为3600秒,’connect_timeout’设置为60秒。 等待超时值远远高于26秒(25899毫秒)。 在exception跟踪中提到。

我使用dbcp进行连接池,这里是数据源的spring bean配置。

           

知道为什么会这样吗? 请问使用c3p0解决问题?

尝试正确设置Apache Commons DBCP。

你需要设置:

  • validationQuery to SELECT 1 + 1
  • testOnBorrow为真

这应该解决问题。

您能描述一下您的应用如何处理连接池吗? 我怀疑JDBC驱动程序中的autoReconnect = true会重新汇集来自您应用的连接。 应用程序在失去连接时需要重新连接。

我会遵循exception中的建议。 你应该考虑:

  1. 在您的申请中使用之前到期和/或测试连接有效性,
  2. 增加服务器配置的客户端超时值,或
  3. 使用Connector / J连接属性’autoReconnect = true’来避免此问题。 尝试将其添加到您的连接URL(请参阅文档以获取确切的语法),看看它是否有帮助。

我怀疑C3P0会比你已经使用的DBCP好得多。 例外情况是给你一些具体的建议。 你试过#3。 那两个呢?

我知道在使用它们之前如何让WebLogic检查连接。 您应该了解如何使用Tomcat执行相同的操作。

我之前看到,已经在网络上移动的Windows机器在连接自己时遇到了麻烦。

JVM之外是否存在任何连接问题 – 即连接到服务器的mysql客户端,以及超时等?