石英调度程序计划时间错误

4

我有一个Spring Boot 应用程序,在其中尝试使用 Quartz 调度程序在每天特定时间运行任务。以下是我构建触发器的代码:

DailyTimeIntervalScheduleBuilder scheduleBuilder = DailyTimeIntervalScheduleBuilder
.dailyTimeIntervalSchedule()
.startingDailyAt(TimeOfDay.hourAndMinuteFromDate(activeStartTime))
.endingDailyAfterCount(1)
.withMisfireHandlingInstructionFireAndProceed();

MutableTrigger trigger = scheduleBuilder.build();

我面临的问题是工作被安排在明天开始。例如,如果我将工作安排在 5月22日16:45 ,则该工作的第一个执行时间将被设置为 5月23日16:45
我尝试使用生成器并使用withIntervalInHours(24)而不是endingDailyAfterCount(1),但结果相同。
我不确定问题出在哪里。
注意:无论我何时安排我的工作,行为都是相同的,即无论我在16:45之前还是之后执行此代码,工作始终安排在明天。
我使用的是spring boot版本 1.5.10 和spring-boot-starter-quartz版本 2.2.5.RELEASE
1个回答

1
你能尝试下面的代码吗?
CalendarIntervalScheduleBuilder schedule = CalendarIntervalScheduleBuilder
                .calendarIntervalSchedule()
                .inTimeZone(TimeZone.getDefault())
                .withIntervalInDays((int) 1)
                .withMisfireHandlingInstructionFireAndProceed();

Trigger trigger = TriggerBuilder
                .newTrigger()
                .startAt(startDateTime)
                .withSchedule(schedule).build();

对于字段startDateTime,请使用当前日期时间。如果您想从May 22 16:45开始,则相应地创建Date对象。
并设置timezone,否则它将选择默认系统时区。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接