mysql - quartz + mysql - 由 : java. sql.SQLException: Lock wait timeout exceeded 引起;尝试重启交易

标签 mysql quartz-scheduler

我在 quartz + mysql + Tomcat7 中遇到了 Lock wait timeout exceeded 问题。当我将一台服务器用于开发和质量检查时,我面临的问题并没有出现,但在部署后我开始在生产环境(有 2 台服务器)中看到问题。

org.quartz.JobPersistenceException: Couldn't store trigger 'trigger1355274000000' for '1355274000000' job:Lock wait timeout exceeded; try restarting transaction [See nested exception: java.sql.SQLException: Lock wait timeout exceeded; try restarting transaction] 
at org.quartz.impl.jdbcjobstore.JobStoreSupport.storeTrigger(JobStoreSupport.java:1270) 
at org.quartz.impl.jdbcjobstore.JobStoreSupport.triggerFired(JobStoreSupport.java:2961) 
at org.quartz.impl.jdbcjobstore.JobStoreSupport$38.execute(JobStoreSupport.java:2871) 
at org.quartz.impl.jdbcjobstore.JobStoreSupport.executeInNonManagedTXLock(JobStoreSupport.java:3788) 
at org.quartz.impl.jdbcjobstore.JobStoreSupport.triggerFired(JobStoreSupport.java:2865) 
at org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:319) 
Caused by: java.sql.SQLException: Lock wait timeout exceeded; try restarting transaction 
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055) 
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956) 
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3515) 
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3447) 
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1951) 
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2101) 
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2554) 
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1761) 
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2046) 
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1964) 
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1949) 
at org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:102) 
at org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:102) 
at org.quartz.impl.jdbcjobstore.StdJDBCDelegate.updateTrigger(StdJDBCDelegate.java:1295) 
at org.quartz.impl.jdbcjobstore.JobStoreSupport.storeTrigger(JobStoreSupport.java:1256) 

这是我的 quartz 配置。

org.quartz.scheduler.instanceName = ApplicationDemoScheduler
org.quartz.scheduler.instanceId = AUTO

org.quartz.threadPool.class=org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount=10
org.quartz.threadPool.threadPriority = 5
org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread=true
org.quartz.scheduler.threadsInheritContextClassLoaderOfInitializer=true
org.quartz.jobStore.misfireThreshold=180000

org.quartz.jobStore.class=org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.StdJDBCDelegate
org.quartz.jobStore.useProperties=false
org.quartz.jobStore.dataSource=qzDS
org.quartz.jobStore.tablePrefix=QRTZ_
org.quartz.jobStore.isClustered=true
org.quartz.jobStore.selectWithLockSQL=select LOCK_NAME from QRTZ_LOCKS where LOCK_NAME=?
org.quartz.jobStore.clusterCheckinInterval = 20000

org.quartz.scheduler.dbFailureRetryInterval=15000


org.quartz.dataSource.qzDS.jndiURL=java:comp/env/jdbc/appDemoJndi

并且这个数据源是引用Tomcat中配置的数据源。

 <Resource name="jdbc/appDemoJndi" auth="Container" type="javax.sql.DataSource"
          username="testuser" password="test_pswd"
          url="jdbc:mysql://localhost/testuser"
          driverClassName="com.mysql.jdbc.Driver"
          initialSize="20" maxWait="5000"
          maxActive="40" maxIdle="5"
         testWhileIdle="true"
          testOnBorrow="true"
          defaultAutoCommit="false"
          maxOpenPreparedStatements="20" 
          validationQuery="select 1"
          poolPreparedStatements="true"/>

我不依赖任何休眠或任何东西。我不太确定此错误是否与任何 quartz 配置或 MYSQL 配置有关。

有遇到同样问题并解决的吗?请帮助...

谢谢。

最佳答案

同样的问题最终增加了事务锁 [mysqld] innodb_lock_wait_timeout=120

关于mysql - quartz + mysql - 由 : java. sql.SQLException: Lock wait timeout exceeded 引起;尝试重启交易,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13832867/

相关文章:

mysql - JOINing 表同时忽略重复项

mysql - 原则 2 中按 UNION 排序

mysql - 将记录表与映射表按负关系连接起来

grails - Cron Expression被多次调用

java - 使用 Quartz 获取数据库连接

php - 使用面向对象的 php 在 mysqli 函数中更新查询

php - 使用带有多个包含的 php 读取和写入数据库

grails - Grails Quartz插件不记得作业执行之间的状态数据吗?

java - 如何使用Java在quartz中从下午2点到晚上11点每30秒触发一次触发器?

c# - 如何在 ASP.NET Web API Core 应用程序上使用 QUARTZ 实现调度程序?