tomcat+mysql部署,每天早晨第一次访问web项目,出现mysql的连接timeout异常:com.mysql.jdbc.exceptions.jdbc4.CommunicationsException或com.atomikos.datasource.ResourceException。

############################################################################
com.atomikos.datasource.ResourceException: XA resource 'center': resume for XID '3139322E3136382E312E35332E746D30303030363030303530:3139322E3136382E312E35332E746D37' raised 0: unknown com.mysql.jdbc.jdbc2.optional.MysqlXAException: The last packet successfully received from the server was 50,024,067 milliseconds ago. The last packet sent successfully to the server was 50,024,068 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. ############################################################################
The error occurred while applying a parameter map.
--- Check the ts_user.ibatorgenerated_selectByExample-InlineParameterMap.
--- Check the statement (query failed).
--- Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:
The last packet successfully received from the server was 232,007,469 milliseconds ago.
The last packet sent successfully to the server was 232,007,485 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.;
nested exception is com.ibatis.common.jdbc.exception.NestedSQLException: --- The error occurred while applying a parameter map.
--- Check the ts_user.ibatorgenerated_selectByExample-InlineParameterMap.
--- Check the statement (query failed).
--- Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:
The last packet successfully received from the server was 232,007,469 milliseconds ago.
The last packet sent successfully to the server was 232,007,485 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.

原因
mysql5连接的等待时间(wait_timeout)默认是8小时。

查看方法

show global variables like 'wait_timeout'; 

查看结果:
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| wait_timeout | 28800 |
+---------------+-------+
1 row in set (0.00 sec)
在wait_timeout时间里,mysql的connection处于等待状态,过了这时间mysql5就关闭了,但是java application的连接池仍然有合法的connection,当你再操作数据库时,就会出现这样的问题。

解决方法
mysql5之前的版本,可以在jdbc连接的url中加入:autoReconnect = true

mysql5中wait_timeout在window中最大为24天,在linux中最大为365天。

a、修改配置

如果在window中设置为21天,改mysql5的安装文件夹中的my.ini
如果在linux中/etc/my.cnf,添加一行:wait_timeout = 1814400,重启mysql,添加效果如下:

b、直接用sql命令行修改(重启有还原为28800,不推荐)

mysql> set global wait_timeout=1814400;
mysql> show global variables like 'wait_timeout';

查看mysql版本

select version();

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException/com.atomikos.datasource.ResourceException异常解决的更多相关文章

  1. com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure 解决办法

    09:00:30.307 [http-8080-6] ERROR org.hibernate.transaction.JDBCTransaction -JDBC begin failed com.my ...

  2. mysql 数据库问题com.mysql.jdbc.exceptions.jdbc4.CommunicationsException

    本文转自:http://blog.csdn.net/zmzsoftware/article/details/6835604 MySQL第二天早上第一次连接超时报错,解决方法com.mysql.jdbc ...

  3. com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure 数据库报错

    -- 查询mysql 数据库链接空闲时间持有最大空闲时间,单位为秒 SHOW VARIABLES WHERE VAriable_name = 'interactive_timeout'; -- 会出现 ...

  4. Oozie时出现Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure?

    不多说,直接上干货! 问题详情 [hadoop@bigdatamaster oozie--cdh5.5.4]$ bin/ooziedb.sh create -sqlfile oozie.sql -ru ...

  5. 异常解决:Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

    异常描述 这个异常通常有如下信息: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failu ...

  6. Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

    很长的报错,截取   ERROR c.a.d.p.DruidDataSource - discard connection   com.mysql.jdbc.exceptions.jdbc4.Comm ...

  7. Caused by: java.net.ConnectException: Connection refused/Caused by: java.lang.RuntimeException: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

    1.使用sqoop技术将mysql的数据导入到Hive出现的错误如下所示: 第一次使用命令如下所示: [hadoop@slaver1 sqoop--cdh5.3.6]$ bin/sqoop impor ...

  8. org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure The last packet sent succ

    数据库 没有开启  连接失败 org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause ...

  9. mysql 5.1超过默认8小时空闲时间解决办法(错误:com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure)

    报错: MySQL第二天早上第一次连接超时报错, com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications lin ...

随机推荐

  1. linux python 图形编程 qt开发环境搭建

    我的系统是 ubuntu14.04 我们使用的是python2.7,建议安装qt4+pyqt4+eric4 eric是pyqt的界面设计器的代码生成软件. 1.安装sip 这个是python和qt之间 ...

  2. Linux下Apache服务器配置

    Linux下Apache服务器配置 相关包: httpd-2.2.3-29.e15.i386.rpm                 //主程序包 httpd-devel-2.2.3-29.e15.i ...

  3. altium布局布线原则

    布局应该先放位置确定不能随意变动的,之后是核心器件,然后是周围器件,如果周围器件过多,为防止布线时交叉过多,可以一部分小模块放到底层. 布线时优先顺序为先电源线和网络中使用频率高的线,之后是信号线.走 ...

  4. 【spring源码学习】spring的事务管理的源码解析

    [一]spring事务管理(1)spring的事务管理,是基于aop动态代理实现的.对目标对象生成代理对象,加入事务管理的核心拦截器==>org.springframework.transact ...

  5. testem方便的web tdd 测试框架使用

    备注:    单元测试,对于日常的开发是比较重要的,testem 简化了我们的代码编写,以及运行.    主要特性:    a. 支持的测试框架有:jasmine quint mocha buster ...

  6. 搭建基于hyperledger fabric的联盟社区(二) --环境配置

    接下来讲一下在本地测试区块链网络的过程.我要部署的是2peer+1orderer架构,所以需要准备三台虚拟机,为了方便起见可以先把一台配置好,然后复制出剩余两台即可.搭建虚拟机我用的是virtualb ...

  7. ssi框架学习总结

    框架简介: 相信大家对于mvc的三层架构已经灰常熟悉了,在这就不细讲了,个人感觉ssi的框架结构还是比较典型的mvc三层架构,还是比较容易上手的.关于这块的入门我想特别感谢下FrankHui童鞋,在他 ...

  8. 嵌入ARM硬核的FPGA

    目前,在FPGA上嵌入ARM硬核的包括Xilinx的zynq系列以及Intel 的CYCLONEV系列. Zynq出来有一定市场,但是这个市场不是传统FPGA的主流市场,而是为了和微处理抢一些控制领域 ...

  9. 怎样用java生成GUID与UUID

    GUID是一个128位长的数字,一般用16进制表示.算法的核心思想是结合机器的网卡.当地时间.一个随机数来生成GUID.从理论上讲,如果一台机器每秒产生10000000个GUID,则可以保证(概率意义 ...

  10. Java-Runoob-面向对象:Java 包(Package)

    ylbtech-Java-Runoob-面向对象:Java 包(Package) 1.返回顶部 1. Java 包(package) 为了更好地组织类,Java 提供了包机制,用于区别类名的命名空间. ...