错误日志简述:
o.q.i.j.JobStoreTX [?:?] Failed to override connection auto commit/transaction isolation.
xxx
Failure obtaining db row lock: Communications link failure
The last packet successfully received from the server was 2,173,381 milliseconds ago. The last packet sent successfully to the server was 19 milliseconds ago.
xxxxxx
Caused by: java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.
Caused by:com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
Caused by: java.net.SocketException: Broken pipe
其实就是一句话,定时任务集群和数据库的链接断掉了。原因呢,参考https://www.cnblogs.com/cyd-shuihan/p/9718099.html
由于测试(28800)仿真(5000)生产(1800)环境的 mysql wait_timeout时间设置的不同,导致这个定时任务的链接报错越来越频繁。主要修改就是更改mysql的全局wait_timeout为默认(28800)或者 quartz的默认配置文件中 增加
org.quartz.dataSource.myDS.validateOnCheckout=true
org.quartz.dataSource.myDS.validationQuery=select 1
org.quartz.dataSource.myDS.discardIdleConnectionsSeconds=60
其中的myDS对应你该配置文件中的
org.quartz.jobStore.dataSource=myDS。
并且 配置项中的大小写一定要检查清楚。参考文章中的这三个配置 大小写就错了俩。。靠。源码debug了俩小时才发现是大小写复制错了。
分析原因的话:其实是因为在quartz默认的集群配置中是没有 校验链接有效性的配置的,当mysql的wait_timeout时间比较少的时候会出现这样的问题。空闲时候定时job默认是不放开链接的,但是mysql在空闲时候会自主断开来接,造成job拿着已经过期的旧船票站在码头发现船没了。然后报错。
另外的话,quartz的配置文件也可以写在xml文件中,配置同理。