[英]Quartz scheduler incorrect schedule time
I have a spring boot application in which I am trying to schedule a job using quartz scheduler to run daily at a specific time of the day.我有一个 spring 启动应用程序,我正在尝试使用石英调度程序安排一个作业,以便每天在一天中的特定时间运行。 The following is my code to build the trigger.
以下是我构建触发器的代码。
DailyTimeIntervalScheduleBuilder scheduleBuilder = DailyTimeIntervalScheduleBuilder
.dailyTimeIntervalSchedule()
.startingDailyAt(TimeOfDay.hourAndMinuteFromDate(activeStartTime))
.endingDailyAfterCount(1)
.withMisfireHandlingInstructionFireAndProceed();
MutableTrigger trigger = scheduleBuilder.build();
The problem I am facing is that the job is scheduled but starting from the next day.我面临的问题是工作已安排但从第二天开始。 So for instance, if I schedule the job for May 22 16:45 , then the first fire time for the job is set to May 23 16:45 .
例如,如果我将作业安排为May 22 16:45 ,那么作业的第一次触发时间将设置为May 23 16:45 。
I have tried using the builder with withIntervalInHours(24)
instead of endingDailyAfterCount(1)
, but the result is the same.我尝试使用带有
withIntervalInHours(24)
而不是endingDailyAfterCount(1)
的构建器,但结果是一样的。
I am not sure what seems to be the problem.我不确定似乎是什么问题。
Note: This behavior is the same regardless of when I schedule my job, ie, it doesn't matter if I execute this code before or after 16:45, the job is always scheduled for the next day注意:无论我何时安排作业,此行为都是相同的,即无论我在 16:45 之前还是之后执行此代码,作业总是安排在第二天
I am using spring boot version 1.5.10 and spring-boot-starter-quartz version 2.2.5.RELEASE我正在使用 spring 启动版本1.5.10和 spring-boot-starter-quartz 版本2.2.5.RELEASE
Can you try below code你可以试试下面的代码
CalendarIntervalScheduleBuilder schedule = CalendarIntervalScheduleBuilder
.calendarIntervalSchedule()
.inTimeZone(TimeZone.getDefault())
.withIntervalInDays((int) 1)
.withMisfireHandlingInstructionFireAndProceed();
Trigger trigger = TriggerBuilder
.newTrigger()
.startAt(startDateTime)
.withSchedule(schedule).build();
For the field startDateTime
please use current Date time.对于字段
startDateTime
,请使用当前日期时间。 if you want to start from May 22 16:45
then create the Date
object accordingly.如果您想从
May 22 16:45
开始,则相应地创建Date
object。
And set the timezone
also, or it will pick default system's timezone.并设置
timezone
,否则它将选择默认系统的时区。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.