繁体   English   中英

如何强制 Quartz 在集群模式下按顺序运行

[英]How to force Quartz to run sequentially in cluster mode

我正在使用 Quartz 和 Spring Boot 作为其中一项服务,尽管有集群配置和 @DisallowConcurrentExecution 注释的使用,但我观察到该作业被多次触发。

有趣的是,这只会在服务重新启动后发生。 几次运行后,作业“将自己”设置为正确的执行模式。

我的配置

spring:
  quartz:
    properties:
      org.quartz.jobStore:
        class: org.quartz.impl.jdbcjobstore.JobStoreTX
        driverDelegateClass: org.quartz.impl.jdbcjobstore.PostgreSQLDelegate
        isClustered: true
        clusterCheckinInterval: 500
        acquireTriggersWithinLock: true
        tablePrefix: qtz_
      org.quartz.scheduler:
        instanceName: CompanyProfileScheduler
        instanceId: AUTO
    job-store-type: jdbc
    jdbc:
      initialize-schema: never

我的工作配置

@Configuration
public class QuartzConfig {

    @Bean
    public JobDetail companyProfilePublishingSchedulerJobDetails() {
        return JobBuilder
                .newJob(CompanyProfilePublishingJob.class)
                .withIdentity("CompanyProfilePublishingScheduler")
                .storeDurably()
                .build();
    }

    @Bean
    public Trigger companyProfilePublishingTrigger(final JobDetail companyProfilePublishingSchedulerJobDetails) {
        return TriggerBuilder
                .newTrigger()
                .forJob(companyProfilePublishingSchedulerJobDetails)
                .withIdentity("CompanyProfilePublishingSchedulerTrigger")
                .withSchedule(
                        SimpleScheduleBuilder
                                .simpleSchedule()
                                .withIntervalInSeconds(CompanyProfilePublishingJob.RUN_INTERVAL_IN_SECONDS)
                                .withMisfireHandlingInstructionNextWithRemainingCount()
                                .repeatForever())
                .build();
    }
}

工作

@Slf4j
@Component
@RequiredArgsConstructor
@DisallowConcurrentExecution
@PersistJobDataAfterExecution
public class CompanyProfilePublishingJob extends QuartzJobBean {
...
}

我认为您需要显示和您的数据库连接属性。 添加注解@DisallowConcurrentExecution 后是否创建了jobDetail? 因为一次只有这个注解存在控制一个作业实例。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM