java - MySQL通信异常

标签 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 会给出 Can not write:broken pipeline"或类似的异常 但在这种情况下,连接并不空闲。这是工作。所以MySQL不会关闭它。但Java正在等待查询结果,12小时内无法获取结果,因此显示“Read Timeout”异常

最佳答案

你需要使用连接池来为你管理这些事情,引用c3po,基本思想是你做一个虚拟查询来定期保持连接 Activity

关于java - MySQL通信异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21570810/

相关文章:

java - 在 Spring AMQP 中检测凭证删除并从中恢复

java - 我可以在关机时进行 Swing 操作吗?

Mysql 多行索引

java - 在 JBoss 4.2.3 中获取 EJB 方法调用者的 IP 地址

java - 使用 Jboss 读取 PropertyPlaceholderConfigurer 类路径 Spring

java - 如何从我的 Dropwizard 资源中访问已包装在自定义类中的请求?

java - 正则表达式未按预期工作

MySQL 服务器已经执行大型脚本文件

java - 是否可以在mysql中将表本身的属性名称作为字符串传递?

java - Jboss 7 getResourcesAsStream()