Почему Quartz Scheduler запускается дважды? - PullRequest
0 голосов
/ 28 ноября 2018

У меня есть веб-приложение Spring MVC, в котором есть Quartz Scheduler для выполнения специальных операций раз в минуту.Для этой цели у меня есть следующий класс:

public class QuartzJobRunner {

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

        log.debug("end");
    }
}

и конфигурация 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.

Что может быть причиной этого?На подобные вопросы здесь нет однозначных ответов.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...