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. 在iOS上实现二维码功能

    http://blog.csdn.net/abcmx/article/details/8011904 如今二维码随处可见,无论是实物商品还是各种礼券都少不了二维码的身影.而手机等移动设备又成为二维码的 ...

  2. scrapy 伪装代理和fake_userAgent的使用

    伪装浏览器代理 在爬取网页是有些服务器对请求过滤的不是很高可以不用ip来伪装请求直接将自己的浏览器信息给伪装也是可以的. 第一中方法: 1.在setting.py文件中加入以下内容,这是一些浏览器的头 ...

  3. 【Netty】netty学习之nio网络编程的模型

    [一]NIO服务器编程结构 [二]Netty3.x服务端线程模型

  4. lua resty template && openresty 使用

    1. 安装 luarocks install lua-resty-template 2. 使用   配置模板页面位置     有多种方式:   a.  直接使用root 目录     代码如下:    ...

  5. chrome扩展程序开发之在目标页面执行自己的JS

    大家都知道JS是执行在client的.所以,假设我们自己写一个浏览器的话.是一定能够往下载下来的网页源码中加入js的.可惜我们没有这个能力.只是幸运的是,chrome的扩展程序能够帮我们做到这件事. ...

  6. 笔记:服务器压缩方案 来源于 Accept-Encoding: gzip, deflate 问题

    笔记:服务器压缩方案 来源于 Accept-Encoding: gzip, deflate 问题 事情起因:odoo demo 没有启动web 压缩 目前流行的 web 压缩技术 gzip br 支持 ...

  7. Python中的url编码问题

    >>> import urllib >>> a = "PythonTab中文网" >>> a 'PythonTab\xe4\x ...

  8. JFreeChart API 说明(转)

    原地址 http://blog.csdn.net/mike_caoyong/article/details/7338160 JFreeChart目前是最好的java图形解决方案,基本能够解决目前的图形 ...

  9. Springboot监控之一:SpringBoot四大神器之Actuator之2--springboot健康检查

    Health 信息是从 ApplicationContext 中所有的 HealthIndicator 的 Bean 中收集的, Spring Boot 内置了一些 HealthIndicator. ...

  10. 杂项:大数据 (巨量数据集合(IT行业术语))

    ylbtech-杂项:大数据 (巨量数据集合(IT行业术语)) 大数据(big data),指无法在一定时间范围内用常规软件工具进行捕捉.管理和处理的数据集合,是需要新处理模式才能具有更强的决策力.洞 ...