MySQL中的通信异常

时间:2014-02-05 07:12:29

标签: java mysql jboss

我正在寻找以下问题的解决方案,如果您有任何想法请分享 当我尝试从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将给出不能写:断管“或类似异常 但在这种情况下,连接不是空闲的。这是工作。所以MySQL不会关闭它。但Java正在等待查询结果,并且无法在12小时内获取它,因此它显示“读取超时”异常

1 个答案:

答案 0 :(得分:2)

你需要使用管理这些东西的连接池,参考c3po,基本的想法是你做一个虚拟查询以保持连接定期活着

相关问题