不同的 Quartz TriggerState 枚举状态代表什么?

发布于 2025-01-07 20:17:17 字数 1491 浏览 0 评论 0原文

不同的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沙与沫 2025-01-14 20:17:17

从代码来看,TriggerState 似乎进入“COMPLETE”状态,然后立即从所有跟踪哈希映射中删除。这就是为什么 scheduler.getTriggerState(triggerKey) 返回 TriggerState.NONE ——当与 triggerKey 对应的触发器不存在时返回此状态。

因此,要检查触发器的完成情况,可以执行以下操作:

if ((triggerState == TriggerState.COMPLETE) || (triggerState == TriggerState.NONE)) {
  // do stuff }

或者

使用自定义的 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 why scheduler.getTriggerState(triggerKey) returns TriggerState.NONE -- this state is returned when the trigger corresponding to the triggerKey does not exist.

So, to check the completion of a trigger, it is possible to do:

if ((triggerState == TriggerState.COMPLETE) || (triggerState == TriggerState.NONE)) {
  // do stuff }

OR

to use a custom TriggerListener that does something when the trigger is complete.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文