有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java基于配置的时间表给定的触发器永远不会触发Quartz

下面是代码

Trigger trigger = TriggerBuilder
            .newTrigger().withIdentity(job.getTriggerName(), job.getGroupName())                    
            .withSchedule(CronScheduleBuilder.cronSchedule(new CronExpression(cronExpression)).inTimeZone(TimeZone.getTimeZone(remoteTimezone)).withMisfireHandlingInstructionFireAndProceed())                 
            .startAt(startDate)
            .endAt(endDate)                 
            .build();

下面是日志

[11-28 15:30:00,906] [pool-1-thread-1] [INFO:QuartzJob:99] job.getStartTimes() - 10:00,11:00,12:00
[11-28 15:30:00,908] [pool-1-thread-1] [INFO:QuartzJob:105] dateValue - Sat Nov 28 15:30:00 IST 2020
[11-28 15:30:00,909] [pool-1-thread-1] [INFO:QuartzJob:105] dateValue - Sat Nov 28 16:30:00 IST 2020
[11-28 15:30:00,910] [pool-1-thread-1] [INFO:QuartzJob:105] dateValue - Sat Nov 28 17:30:00 IST 2020
[11-28 15:30:00,913] [pool-1-thread-1] [INFO:QuartzJob:130] mins --- 30
[11-28 15:30:00,913] [pool-1-thread-1] [INFO:QuartzJob:131] hours --- 15,16,17
[11-28 15:30:00,913] [pool-1-thread-1] [INFO:QuartzJob:132] Timezone startDate --- Sat Nov 28 15:30:00 IST 2020
[11-28 15:30:00,913] [pool-1-thread-1] [INFO:QuartzJob:133] Timezone endDate --- Sat Nov 28 17:30:00 IST 2020
[11-28 15:30:00,913] [pool-1-thread-1] [INFO:QuartzJob:137] Generated cronExpression for the Job is - 0 30 15,16,17 * * ?

作业开始时间值以GMT为单位,转换为IST并生成Cron表达式。 但是得到下面的错误

[11-28 15:30:00,936] [pool-1-thread-1] [ERROR:JobExecutor:71] org.quartz.SchedulerException: Based on configured schedule, the given trigger '2020-11-28-DUMMY_JOB_TEST-Jobs.2020-11-28-DUMMY_JOB_TEST-Trigger' will never fire.

不明白为什么会发生这种情况 具有startNow()也会收到相同的错误

任何帮助都将不胜感激


共 (1) 个答案

  1. # 1 楼答案

    看起来你的开始和日期是一样的:

    Timezone startDate - Sat Nov 28 15:30:00 IST 2020 Timezone endDate - Sat Nov 28 17:30:00 IST 2020

    它们仅在几个小时内有所不同,但quartz调度程序的工作方式是,结束日期必须至少比开始日期晚一天。 您可以通过删除.endAt(endDate)来尝试测试,它应该可以工作