不同的 Quartz TriggerState 枚举状态代表什么?
不同的 Quartz TriggerState 枚举状态代表什么以及它们如何设置?
我有一个 Spring 3.1 Quartz 2.0.1 实用程序用于运行计划作业。我的工作只重复固定次数。我希望当所有工作完成后,我的 TriggerState 会变为 COMPLETE。然而,我看到它从正常变为无,而且我从未看到完整。我找不到太多有关 TriggerState 行为的文档。
相关Java代码:
SchedulerFactory schedFactory = new StdSchedulerFactory();
Scheduler scheduler = = schedFactory.getScheduler();
scheduler.scheduleJob(jobDetail, trigger);
scheduler.start();
while (System.in.available() == 0) {
// Get trigger state
TriggerState triggerState = scheduler.getTriggerState(triggerKey);
if ((triggerState == TriggerState.COMPLETE)) {
break;
}
// Sleep for 100 msec
Thread.sleep(SCHEDULER_SLEEP_TIME);
}
Spring xml中的作业配置:
<bean id="mockJobDetail"
class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
<property name="jobClass"
value="mypackage.MockJob"/>
</bean>
<bean id="simpleMockJobTrigger"
class="org.quartz.impl.triggers.SimpleTriggerImpl" >
<property name="name" value="simpleMockJobTrigger" />
<!-- run every 50 milliseconds and start immediately, run 3 times -->
<property name="repeatInterval" value="50" />
<property name="startTime">
<bean factory-bean="dateFormat" factory-method="parse">
<constructor-arg value="2012-01-01" />
</bean>
</property>
<property name="repeatCount" value="2" />
</bean>
What do different Quartz TriggerState enum states represent and how do they get set?
I have a Spring 3.1 Quartz 2.0.1 utility used to run scheduled jobs. My jobs only repeat a fixed number of times. I expect that my TriggerState to go to COMPLETE when all the jobs are done. However, I see it go from NORMAL to NONE and I never see COMPLETE. I couldn't find much documentation on TriggerState behavior.
Relevant Java code:
SchedulerFactory schedFactory = new StdSchedulerFactory();
Scheduler scheduler = = schedFactory.getScheduler();
scheduler.scheduleJob(jobDetail, trigger);
scheduler.start();
while (System.in.available() == 0) {
// Get trigger state
TriggerState triggerState = scheduler.getTriggerState(triggerKey);
if ((triggerState == TriggerState.COMPLETE)) {
break;
}
// Sleep for 100 msec
Thread.sleep(SCHEDULER_SLEEP_TIME);
}
Job configuration in Spring xml:
<bean id="mockJobDetail"
class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
<property name="jobClass"
value="mypackage.MockJob"/>
</bean>
<bean id="simpleMockJobTrigger"
class="org.quartz.impl.triggers.SimpleTriggerImpl" >
<property name="name" value="simpleMockJobTrigger" />
<!-- run every 50 milliseconds and start immediately, run 3 times -->
<property name="repeatInterval" value="50" />
<property name="startTime">
<bean factory-bean="dateFormat" factory-method="parse">
<constructor-arg value="2012-01-01" />
</bean>
</property>
<property name="repeatCount" value="2" />
</bean>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从代码来看,TriggerState 似乎进入“COMPLETE”状态,然后立即从所有跟踪哈希映射中删除。这就是为什么
scheduler.getTriggerState(triggerKey)
返回TriggerState.NONE
——当与triggerKey
对应的触发器不存在时返回此状态。因此,要检查触发器的完成情况,可以执行以下操作:
或者
使用自定义的 TriggerListener 在触发器完成时执行某些操作。
From looking at the code, it looks like the TriggerState goes to
COMPLETE
state and is then immediately removed from all tracking hash maps. That is whyscheduler.getTriggerState(triggerKey)
returnsTriggerState.NONE
-- this state is returned when the trigger corresponding to thetriggerKey
does not exist.So, to check the completion of a trigger, it is possible to do:
OR
to use a custom
TriggerListener
that does something when the trigger is complete.