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. Emgucv3.0的安装与配置

    环境:vs2015+Emgucv3.0 Emgu Cv简介: Emgu CV 是.NET平台下对OpenCV图像处理库的封装.也就是OpenCV的.NET版.它运行在.NET兼容的编程语言下调用Ope ...

  2. LeetCode Find Permutation

    原题链接在这里:https://leetcode.com/problems/find-permutation/description/ 题目: By now, you are given a secr ...

  3. asp搭建网站

    测试环境:Windows 2003 下载asp源码导入 C:\Inetpub\wwwroot ###一.通过ip访问 最后浏览 浏览器输入ip或者 http://127.0.0.1 二.通过域名访问 ...

  4. k8s helm 私服chartmuseum minio s3 存储配置

    1. 安装minio 使用docker 安装 参考项目 https://github.com/rongfengliang/mino-thumbor-openresty 备注: 因为是一个集成项目可能会 ...

  5. ORACLE联机日志文件丢失或损坏的处理方法(转)

    经验总结: 联机日志分为当前联机日志和非当前联机日志,非当前联机日志的损坏是比较简单的,一般通过clear命令就可以解决问题. 损坏非当前联机日志:1.启动数据库,遇到ORA-00312 or ORA ...

  6. 浅谈splay

    \(BST\) 二叉查找树,首先它是一颗二叉树,其次它里面每个点都满足以该点左儿子为根的子树里结点的值都小于自己的值,以该点右儿子为根的子树里结点的值都大于自己的值.如果不进行修改,每次查询都是\(O ...

  7. MEF学习总结(3)---Attribute Model Programing

    上一片介绍了Primitive层,Attribute Model可以认为是对Primitive的上层实现.主要包括如下内容: 1. 一系列的Attribute来定义Import和Export 常用的有 ...

  8. c++里面有没有什么办法做到 判断某个给定的未知数是double类型还是int类型 呢?

    c++里面有没有什么办法做到 判断某个给定的未知数是double类型还是int类型 呢? 如果只是double和int, 可以用sizeof 1 2 3 4 5 6 7 8 9 10 11 12 13 ...

  9. Ubuntu 16.04 配置安卓5.1编译环境

    Ubuntu 16.04版本 电脑cpu必须是64位 硬盘分配大约100G的空间 1.ubuntu中更新源 $ sudo apt-get update 2.安装 openjdk-8-jdk $ sud ...

  10. ShowDialog窗体的return问题

    最近的一个项目里,打开新窗口用到了ShowDialog()这种方式,发现在新窗口做保存操作的时候,保存按钮事件下的程序执行完(无论有没有return)都会关闭子窗口. 网上查了一下,发现大家说的方法在 ...