我正在寻找以下问题的解决方案,如果您有任何想法请分享 当我尝试从 java(jboss 服务器)运行单个查询时,出现以下异常(不频繁)。
Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:
The last packet successfully received from the server was43200 seconds ago. The last packet sent successfully to the server was 43200 seconds 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 将关闭它。在这种情况下,Java 会给出 Can not write:broken pipeline"或类似的异常 但在这种情况下,连接并不空闲。这是工作。所以MySQL不会关闭它。但Java正在等待查询结果,12小时内无法获取结果,因此显示“Read Timeout”异常
最佳答案
你需要使用连接池来为你管理这些事情,引用c3po,基本思想是你做一个虚拟查询来定期保持连接 Activity
关于java - MySQL通信异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21570810/