即使使用连接validation,Tomcat JDBC Conencton Pool + MySQL也会出现“Broken pipe”问题

我正在努力配置Tomcat JDBC连接池以实现可靠性。 目前的问题是在测试环境中我在webapp中有这样的scanerio:

  • 第1天:一切正常
  • 第2天:webapp几个小时都无法与MySQL通信,日志中有很多“破管”
  • 第3天:令人惊讶的是,一切都恢复正常(没有注册或重启)

我已经配置了validationIntervalvalidationQueryvalidationTimeout 。 这是我的数据源配置:

                   

我在连接URL中没有autoReconnect=true参数,只有UTF8编码。

确切的错误是:

 Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 38,700,615 milliseconds ago. The last packet sent successfully to the server was 38,700,615 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. Caused by: java.net.SocketException: Broken pipe 

我们的一个应用程序遇到了类似的问题,经过大量挖掘后,我们添加了以下属性来解决所有连接问题:

 maxAge="180000" testOnBorrow="true" testWhileIdle="true" validationInterval="0" //forces the connection pool to validate each time a connection is given to the application 

您需要将’testOnBorrow’设置为’true’,并且可能将’maxAge’设置为小于服务器配置的’wait_timeout’,如消息中暗示的那样。