jdbc4.CommunicationsException - 神秘的超时

时间:2012-11-20 17:08:22

标签: java mysql jdbc c3p0

日志信息全文:

Log Message: An error occurred while grabbing new users com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 44,567,434 milliseconds ago. The last packet sent successfully to the server was 44,567,434 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.

这对我来说很奇怪,因为这超过了10个小时。我的程序在过去的10个小时内愉快而成功地运行,包括与数据库通信。我得到的最好假设是池中的单个连接是陈旧的,但在这种情况下,我不知道为什么不会自动清除或者此异常与该操作有关。我该怎么办呢?

使用c3p0连接池。

1 个答案:

答案 0 :(得分:1)

c3p0有很多方法可以测试Connections并防止它们超时或过时。解决您遇到的特定问题的最简单方法是将配置参数maxIdleTime设置为8小时(28800秒)。

但您可能希望一般地开始测试Connections,例如,将idleConnectionTest周期设置为频繁的并将testConnectionOnCheckin设置为true。见...

http://www.mchange.com/projects/c3p0/#configuring_connection_testing

http://www.mchange.com/projects/c3p0/#configuration_properties