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

时间:2012-02-21 00:23:03

标签: java quartz-scheduler

不同的Quartz TriggerState枚举状态代表什么以及如何设置?

我有一个用于运行预定作业的Spring 3.1 Quartz 2.0.1实用程序。我的工作只重复固定次数。我希望在完成所有作业后,我的TriggerState将转到COMPLETE。但是,我看到它从NORMAL到NONE,我从未看到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>

1 个答案:

答案 0 :(得分:3)

从查看代码看,TriggerState看起来像COMPLETE状态,然后立即从所有跟踪哈希映射中删除。这就是scheduler.getTriggerState(triggerKey)返回TriggerState.NONE的原因 - 当triggerKey对应的触发器不存在时返回此状态。

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

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

OR

使用在触发器完成时执行某些操作的自定义TriggerListener