问题描述
我是JSP和Quartz调度的新手!在这个项目中,我试图使石英调度程序继续运行,以防服务器关闭然后忽略丢失的作业.
I'm new to JSP and Quartz Scheduling! In this project, I'm trying to make the quartz scheduler continue functioning in case the server is turned off then on ignoring the missed jobs.
为此,我研究了JobPersistence,并修改了crystal.properties文件,如下所示:
For this, I researched JobPersistence and I have modified the quartz.properties file as the following:
org.quartz.threadPool.threadCount=5
org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.jobStore.tablePrefix = QRTZ_
org.quartz.jobStore.useProperties = true
org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.StdJDBCDelegate
org.quartz.jobStore.dataSource = myDB
org.quartz.dataSource.myDB.driver = com.mysql.jdbc.Driver
org.quartz.dataSource.myDB.URL = jdbc:mysql://localhost:3306/contacts
org.quartz.dataSource.myDB.user = root
org.quartz.dataSource.myDB.password = root
web.xml文件包含以下内容:
the web.xml file contains the following:
...
<listener>
<listener-class>
org.quartz.ee.servlet.QuartzInitializerListener
</listener-class>
</listener>
...
我已将表添加到数据库中,当我选择时,可以看到它确实在其表中插入了触发器.
I've added the tables to the DB and when I select I can see that it really inserted triggers to its tables.
触发器的构造如下:
Trigger trig = TriggerBuilder
.newTrigger()
.startAt(scal.getTime())
.withSchedule(
SimpleScheduleBuilder.simpleSchedule()
.withIntervalInMinutes(minutes).repeatForever())
.endAt(ecal.getTime()).build();
现在,当我运行Web应用程序时,我计划了一个作业并执行.然后,我关闭tomcat服务器,然后重新启动它.它将以下错误输出到记录器:
Now, when I run my web app, I schedule a job and it executes. Then, I turn off the tomcat server and start it again. It prints the following error to the logger:
org.quartz.SchedulerConfigException: Failure occured during job recovery. [See nested exception: org.quartz.JobPersistenceException: Couldn't recover jobs: null [See nested exception: java.lang.NullPointerException]]
我尝试在MySQLWorkbench中执行一次以下语句:
I have tried executing the following statement once in MySQLWorkbench:
UPDATE QRTZ_TRIGGERS SET NEXT_FIRE_TIME=1 WHERE NEXT_FIRE_TIME < 0;
现在,我收到了这个新错误:
Now, I got this new error:
.manage - MisfireHandler: Error handling misfires: Unexpected runtime exception: null
org.quartz.JobPersistenceException: Unexpected runtime exception: null [See nested exception: java.lang.NullPointerException]
如果您要我编辑并包括stackTrace,我可以这样做...
If you want me to edit and include the stackTrace, I can do that...
推荐答案
删除useProperties = true
并将其替换为
org.quartz.scheduler.misfirePolicy = doNothing
删除UPDATE
删除触发器上方的所有.withMisfireHandling()
方法,并删除JobDetail
在JobDetail
上的.requestRecovery(true)
(如果使用的话).
remove any .withMisfireHandling()
methods on top of your Trigger and remove the .requestRecovery(true)
on your JobDetail
in case you used it.
此外,请确保不要取消该作业的存在...
Also, make sure you don't cancel the Job in case it exists...
这篇关于Quartz错误失火处理和作业恢复失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!