MySQL db错误后Quartz作业失败

时间:2015-02-27 09:23:07

标签: grails quartz-scheduler

在正在运行的Grails 2.2.5系统中,我们偶尔会失去与MySQL数据库的连接,原因与此处无关。大部分系统从停电中恢复得很好。但任何Quartz作业(使用Quartz插件0.4.2)通常都会在中断后再次运行。这是一个典型的消息,它出现在作业运行点的日志中:

2015-02-26 16:30:45,304 [quartzScheduler_Worker-9] ERROR core.ErrorLogger  - Unable to notify JobListener(s) of Job to be executed: (Job will NOT be executed!). trigger= GRAILS_JOBS.quickQuoteCleanupJob job= GRAILS_JOBS.com.aire.QuickQuoteCleanupJob
org.quartz.SchedulerException: JobListener 'sessionBinderListener' threw exception: Already value [org.springframework.orm.hibernate3.SessionHolder@593a9498] for key [org.hibernate.impl.SessionFactoryImpl@c8488d7] bound to thread [quartzScheduler_Worker-9] [See nested exception: java.lang.IllegalStateException: Already value [org.springframework.orm.hibernate3.SessionHolder@593a9498] for key [org.hibernate.impl.SessionFactoryImpl@c8488d7] bound to thread [quartzScheduler_Worker-9]]
        at org.quartz.core.QuartzScheduler.notifyJobListenersToBeExecuted(QuartzScheduler.java:1868)
        at org.quartz.core.JobRunShell.notifyListenersBeginning(JobRunShell.java:338)
        at org.quartz.core.JobRunShell.run(JobRunShell.java:176)
        at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:525)
Caused by: java.lang.IllegalStateException: Already value [org.springframework.orm.hibernate3.SessionHolder@593a9498] for key [org.hibernate.impl.SessionFactoryImpl@c8488d7] bound to thread [quartzScheduler_Worker-9]
        at org.quartz.core.QuartzScheduler.notifyJobListenersToBeExecuted(QuartzScheduler.java:1866)
        ... 3 more

我需要做些什么来使事情更加健壮,以便Quartz作业也能恢复?

1 个答案:

答案 0 :(得分:1)

默认情况下,Quartz作业将获得绑定到它的会话。禁用该会话绑定并让您的服务处理事务/会话。这就是我们的工作,当我们恢复数据库连接时,工作仍然有效。

要在作业中禁用会话绑定,请添加:

def sessionRequired = false