java - 连接池在 Tomcat 7 中静默过期但 autoReconnect=true 没有修复它

标签 java server tomcat7 ubuntu-14.04 connection-pooling

几周来我一直收到这些异常,但没有解决方案...

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 179,695,604 milliseconds ago.

The last packet sent successfully to the server was 179,695,604 milliseconds ago. 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

所以我更改了我的应用程序的 Context.xml 以在我的数据库中设置 autoReconnect=true 标记,以便在 Tomcat 7 中进行连接池。我什至将 wait_timeout 设置为上下文文件中的无穷大。

我错过了什么?这是个常见的问题吗?网上似乎只有少量信息,但当我按照这些指南进行操作时,在一段时间不活动后第二天又发生了同样的事情。

我使用服务器的次数越多,这种情况就越少发生。我认为这是池连接到期,但如果 wait_timeout 失败,我如何才能阻止它们到期?关于如何诊断问题或配置文件的任何想法?

最佳答案

我遇到了类似的问题,autoReconnect=true 抛出 CommunicationsException 异常,但随后创建了一个到 mysql 的新连接。所以下一个请求会成功。此行为将继续发生,空闲时间后的第一个请求将失败。 为了补充 Alex 已经回答的内容,我将以下参数添加到我的 JDBC 连接字符串中,我再也看不到错误了。

 testOnBorrow="true" validationQuery="SELECT 1" validationInterval="60000"

testOnBorrow 的描述充分说明了这一点。好处是我不必对我的代码进行任何更改。

引用资料: https://tomcat.apache.org/tomcat-7.0-doc/jdbc-pool.html http://www.tomcatexpert.com/blog/2010/04/01/configuring-jdbc-pool-high-concurrency

关于java - 连接池在 Tomcat 7 中静默过期但 autoReconnect=true 没有修复它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34842004/

相关文章:

java - 从 Java 客户端查找 Weblogic ConnectionFactory

php - 如何从 PHP 清除 Opencart 中的缓存

apache - 酒井和多域

java - 无法从 HTML 中的另一个目录加载 Java 小程序

java - 创建两个相同长度的字符串,一个重复另一个的结构,同时一遍又一遍地循环相同的字母

java - 具有多行摘要的自定义 Android 通知 BigPicture 不适用于 API 25 和 API 26

node.js - 如何在 CentOS 服务器上安装 Parse Server?

php - 优化 Wordpress 图片上传,在 Dedicated 上速度慢且一次只能上传 1 张

java - 加载或实例化 TagLibraryValidator 类失败 | Tomcat 7、Eclipse STS

tomcat - 无法访问Tomcat7管理界面