Java 石英作业在服务器关闭后重新触发
最近,我开始使用具有以下属性的Quartz持久作业存储:Java 石英作业在服务器关闭后重新触发,java,spring,quartz-scheduler,Java,Spring,Quartz Scheduler,最近,我开始使用具有以下属性的Quartz持久作业存储: org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.PostgreSQLDelegate 我在spring中使用基于cron的触发器定义了一个示例作业: <bean id="sampleCronTrigge
org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.PostgreSQLDelegate
我在spring中使用基于cron的触发器定义了一个示例作业:
<bean id="sampleCronTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail" ref="sampleJobDetail"/>
<property name="cronExpression" value="0/5 * * * * ?"/>
}
重新启动后的输出如下所示:
Executing the job Job Mon Mar 31 08:34:18 IDT 2014
Executing the job Job Mon Mar 31 08:34:18 IDT 2014
Executing the job Job Mon Mar 31 08:34:18 IDT 2014
然后每5秒它就会再次工作
Executing the job Job Mon Mar 31 08:34:20 IDT 2014
Executing the job Job Mon Mar 31 08:34:25 IDT 2014
在实际应用程序中,我将实现清理数据库的作业(当然,它不会每5秒运行一次:),但我确实计划有时服务器将重新启动并停机一段时间,我希望此作业在重新启动后仅执行一次。有可能吗
我使用SchedulerFactoryBean进行以下配置:
<bean id="quartzSchedulerFactoryBean" class="org.springframework.scheduling.quartz.SchedulerFactoryBean" destroy-method="destroy">
<property name="configLocation" value="classpath:scheduler-quartz.properties"/>
<property name="quartzProperties" ref="qrtzProperties"/>
<property name="autoStartup" value="true" />
<property name="triggers">
<list>
<ref bean="sampleCronTrigger"/>
</list>
</property>
</bean>
提前感谢尝试在sampleCronTrigger上设置缺火指令:
<property name="misfireInstructionName" value="MISFIRE_INSTRUCTION_DO_NOTHING"/>
这是一篇关于的大文章,您也可以尝试设置以下属性
<property name="overwriteExistingJobs" value="true"/>
您使用的是org.springframework.scheduling.quartz.SchedulerFactoryBean吗?是的,我已经更新了问题,在调度quarts时,它甚至会在应用程序完全启动之前触发事件。但通常不会注意到这一点,但在这里,您的应用程序以5秒的间隔触发,因此您会注意到它!!这就是我所相信的。请让我弄清楚,如果服务器需要20秒启动,它将运行几乎3次。因为quarts在前5秒内处于活动状态。看起来Quartz在无法执行作业的时间内执行作业,因为应用程序未运行。尝试添加System.out.println(“作业应在“+context.getScheduledRetime()处执行”)代码>到你的工作。看起来它没有解决问题。但无论如何,谢谢你给我指明这个方向,我会继续在这里挖掘+我这里肯定有10分:)非常感谢,geoand!这解决了问题(至少在POC级别上)!
<property name="overwriteExistingJobs" value="true"/>