石英调度程序错误地分类了作业以恢复

发布于 2025-01-27 12:44:41 字数 1834 浏览 2 评论 0原文

当我在计算机中运行两个应用程序的实例时。其中一个实例可以接收执行的作业,而其他实例则选择相同的作业以恢复。

根据文档,下面的财产应照顾在多个实例上分发工作。但是,其中一个实例正在选择相同的工作以恢复。

org.quartz.jobStore.isClustered = true

使用Quartz-2.3.2

Quartz.properties


org.quartz.scheduler.instanceId = AUTO
org.quartz.scheduler.instanceName = JobScheduler
org.quartz.threadPool.threadCount = 1

org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.StdJDBCDelegate
org.quartz.jobStore.dataSource = ss
org.quartz.jobStore.isClustered = true

org.quartz.dataSource.ss.driver = com.mysql.jdbc.Driver
org.quartz.dataSource.ss.URL = jdbc:mysql://localhost:3306/ss
org.quartz.dataSource.ss.user = root
org.quartz.dataSource.ss.password = password


代码代码段至

JobDetail jobDetail = JobBuilder
        .newJob(JobService.class)
        .requestRecovery(true)
        .withIdentity(promotionJob.getId().toString(), RulesPromotionConstants.JOB_SCHEDULER_GROUP)
        .build();
    // see if jobdatamap needs to be added above

    Trigger trigger = TriggerBuilder
        .newTrigger()
        .forJob(jobDetail)
        .startAt(Date.from(Instant.ofEpochMilli(promotionJob.getScheduledAt())))
        .withSchedule(SimpleScheduleBuilder.simpleSchedule().withMisfireHandlingInstructionFireNow())
        .withIdentity(promotionJob.getId().toString(), RulesPromotionConstants.JOB_TRIGGER_SCHEDULER_GROUP)
        .build();

    rulesPromotionScheduler.scheduleJob(jobDetail, trigger);

代码段下方的sschedulejob,如果在实例已经执行相同作业时执行条件,则使用。

if (jobExecutionContext.isRecovering()) {
    loggerService.getLogger().debug("JobId {} is being recovered",job.getId());
    undoPreparationState(job);
}

注意: - 作业需要几秒钟到几分钟才能执行。

When I am running two instances of the application in a machine. One of the instance picks up the job for execution and other instance picks up the same job for recovery.

As per the documentation, below property should take care of distributing the work across multiple instances. However, one of the instance is picking the same job for recovery.

org.quartz.jobStore.isClustered = true

Using Quartz-2.3.2

quartz.properties


org.quartz.scheduler.instanceId = AUTO
org.quartz.scheduler.instanceName = JobScheduler
org.quartz.threadPool.threadCount = 1

org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.StdJDBCDelegate
org.quartz.jobStore.dataSource = ss
org.quartz.jobStore.isClustered = true

org.quartz.dataSource.ss.driver = com.mysql.jdbc.Driver
org.quartz.dataSource.ss.URL = jdbc:mysql://localhost:3306/ss
org.quartz.dataSource.ss.user = root
org.quartz.dataSource.ss.password = password


Code snippet to sscheduleJob

JobDetail jobDetail = JobBuilder
        .newJob(JobService.class)
        .requestRecovery(true)
        .withIdentity(promotionJob.getId().toString(), RulesPromotionConstants.JOB_SCHEDULER_GROUP)
        .build();
    // see if jobdatamap needs to be added above

    Trigger trigger = TriggerBuilder
        .newTrigger()
        .forJob(jobDetail)
        .startAt(Date.from(Instant.ofEpochMilli(promotionJob.getScheduledAt())))
        .withSchedule(SimpleScheduleBuilder.simpleSchedule().withMisfireHandlingInstructionFireNow())
        .withIdentity(promotionJob.getId().toString(), RulesPromotionConstants.JOB_TRIGGER_SCHEDULER_GROUP)
        .build();

    rulesPromotionScheduler.scheduleJob(jobDetail, trigger);

Below code snippet, if condition is being executed while the one of the instance is already executing the same job.

if (jobExecutionContext.isRecovering()) {
    loggerService.getLogger().debug("JobId {} is being recovered",job.getId());
    undoPreparationState(job);
}

Note:- The job takes few seconds to few minutes to execute.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文