今天调试quartz定时任务时出现一个问题:列如我的定时任务是每天00:00:00触发,我修改当前时间为2015-05-20 23:59:30,30秒后就会准时执行,错误是发生在我修改时间以后。时间修改为2015-05-21 23:59:30;30秒后定时任务触发,但是出现了一个异常:
Communications link failure,The last packet successfully received from the server was *** millisecond ago.The last packet successfully sent to the server was *** millisecond ago。
百度了下:
MySQL服务器默认的“wait_timeout”是28800秒即8小时,意味着如果一个连接的空闲时间超过8个小时,MySQL将自动断开该连接,而连接池却认为该连接还是有效的(因为并未校验连接的有效性),当应用申请使用该连接时,就会导致上面的报错。
so:解决方案就是修改mysql的配置文件
# SERVER SECTION
# ----------------------------------------------------------------------
#
# The following options will be read by the MySQL Server. Make sure that
# you have installed the server correctly (see above) so it reads this
# file.
#
[mysqld]
wait_timeout=1814400
interactive_timeout=1814400
# The TCP/IP Port the MySQL Server will listen on
port=3306
在[mysqld]
后加上wait_timeout=1814400
interactive_timeout=1814400
注意一定要都加上,网上说的只加上一句并没有效果;
wait_timeout windows系统最大值是1814400(24天) linux是31536000(一年)
加上后保存重启mysql服务
mysql> show variables like 'wait_timeout';
+---------------+---------+
| Variable_name | Value |
+---------------+---------+
| wait_timeout | 1814400 |
+---------------+---------+
1 row in set
问题解决