为什么Quartz Scheduler运行两次?

时间:2018-11-28 07:28:42

标签: java spring-mvc quartz-scheduler

我有一个Spring MVC Web应用程序,该应用程序具有Quartz Scheduler,用于每分钟执行一次特殊操作。为此,我开设了以下课程:

public class QuartzJobRunner {

    public void run() {
        log.debug("start");

        log.debug("end");
    }
}

和调度程序servlet中的XML配置:

<bean id="quartzJobRunner" class="com.demo.quartz.QuartzJobRunner" />

<bean id="methodInvokingJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"
      p:targetObject-ref="quartzJobRunner" p:targetMethod="run"/>

<bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean"
      p:jobDetail-ref="methodInvokingJobDetail" p:cronExpression="0 0/1 * * * ?"/>

<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean" p:triggers-ref="cronTrigger"/>

此处的预期行为是每分钟执行一次run方法。但是该方法执行了两次。

当我查看日志时,看到创建了两个调度程序:

2018-11-28 10:54:04.483 INFO [on(5)-127.0.0.1] org.quartz.impl.StdSchedulerFactory.instantiate  Using default implementation for ThreadExecutor
2018-11-28 10:54:04.518 INFO [on(5)-127.0.0.1] org.quartz.core.SchedulerSignalerImpl.<init>  Initialized Scheduler Signaller of type: class org.quartz.core.SchedulerSignalerImpl
2018-11-28 10:54:04.519 INFO [on(5)-127.0.0.1] org.quartz.core.QuartzScheduler.<init>  Quartz Scheduler v.2.3.0 created.
2018-11-28 10:54:04.520 INFO [on(5)-127.0.0.1] org.quartz.simpl.RAMJobStore.initialize  RAMJobStore initialized.
2018-11-28 10:54:04.522 INFO [on(5)-127.0.0.1] org.quartz.core.QuartzScheduler.initialize  Scheduler meta-data: Quartz Scheduler (v2.3.0) 'org.springframework.scheduling.quartz.SchedulerFactoryBean#0' with instanceId 'NON_CLUSTERED'
  Scheduler class: 'org.quartz.core.QuartzScheduler' - running locally.
  NOT STARTED.
  Currently in standby mode.
  Number of jobs executed: 0
  Using thread pool 'org.quartz.simpl.SimpleThreadPool' - with 10 threads.
  Using job-store 'org.quartz.simpl.RAMJobStore' - which does not support persistence. and is not clustered.

2018-11-28 10:54:04.522 INFO [on(5)-127.0.0.1] org.quartz.impl.StdSchedulerFactory.instantiate  Quartz scheduler 'org.springframework.scheduling.quartz.SchedulerFactoryBean#0' initialized from an externally provided properties instance.
2018-11-28 10:54:04.522 INFO [on(5)-127.0.0.1] org.quartz.impl.StdSchedulerFactory.instantiate  Quartz scheduler version: 2.3.0
2018-11-28 10:54:04.525 INFO [on(5)-127.0.0.1] org.quartz.core.QuartzScheduler.setJobFactory  JobFactory set to: org.springframework.scheduling.quartz.AdaptableJobFactory@4e6e5412
2018-11-28 10:54:04.569 INFO [on(5)-127.0.0.1] org.quartz.core.QuartzScheduler.start  Scheduler org.springframework.scheduling.quartz.SchedulerFactoryBean#0_$_NON_CLUSTERED started.
2018-11-28 10:54:04.570 DEBUG [SchedulerThread] org.quartz.core.QuartzSchedulerThread.run  batch acquisition of 0 triggers
2018-11-28 10:54:04.842 INFO [on(5)-127.0.0.1] org.quartz.impl.StdSchedulerFactory.instantiate  Using default implementation for ThreadExecutor
2018-11-28 10:54:04.844 INFO [on(5)-127.0.0.1] org.quartz.core.SchedulerSignalerImpl.<init>  Initialized Scheduler Signaller of type: class org.quartz.core.SchedulerSignalerImpl
2018-11-28 10:54:04.844 INFO [on(5)-127.0.0.1] org.quartz.core.QuartzScheduler.<init>  Quartz Scheduler v.2.3.0 created.
2018-11-28 10:54:04.845 INFO [on(5)-127.0.0.1] org.quartz.simpl.RAMJobStore.initialize  RAMJobStore initialized.
2018-11-28 10:54:04.845 INFO [on(5)-127.0.0.1] org.quartz.core.QuartzScheduler.initialize  Scheduler meta-data: Quartz Scheduler (v2.3.0) 'org.springframework.scheduling.quartz.SchedulerFactoryBean#0' with instanceId 'NON_CLUSTERED'
  Scheduler class: 'org.quartz.core.QuartzScheduler' - running locally.
  NOT STARTED.
  Currently in standby mode.
  Number of jobs executed: 0
  Using thread pool 'org.quartz.simpl.SimpleThreadPool' - with 10 threads.
  Using job-store 'org.quartz.simpl.RAMJobStore' - which does not support persistence. and is not clustered.

2018-11-28 10:54:04.845 INFO [on(5)-127.0.0.1] org.quartz.impl.StdSchedulerFactory.instantiate  Quartz scheduler 'org.springframework.scheduling.quartz.SchedulerFactoryBean#0' initialized from an externally provided properties instance.
2018-11-28 10:54:04.846 INFO [on(5)-127.0.0.1] org.quartz.impl.StdSchedulerFactory.instantiate  Quartz scheduler version: 2.3.0
2018-11-28 10:54:04.846 INFO [on(5)-127.0.0.1] org.quartz.core.QuartzScheduler.setJobFactory  JobFactory set to: org.springframework.scheduling.quartz.AdaptableJobFactory@27473d57
2018-11-28 10:54:04.864 DEBUG [SchedulerThread] org.quartz.core.QuartzSchedulerThread.run  batch acquisition of 0 triggers
2018-11-28 10:54:04.864 INFO [on(5)-127.0.0.1] org.quartz.core.QuartzScheduler.start  Scheduler org.springframework.scheduling.quartz.SchedulerFactoryBean#0_$_NON_CLUSTERED started.

这可能是什么原因?这里类似的问题没有明确的答案。

0 个答案:

没有答案