Question

I'm trying to create a quartz job that runs daily at 10:00 AM, but first start at 9:30 AM. I'm doing it using start time and cron expression as follows:

CronTrigger newTrigger = newTrigger().withIdentity(jobName + i, jobName)
   .startAt(startTime).endAt(endTime).withSchedule(cronSchedule(cronExpression)
   .withMisfireHandlingInstructionFireAndProceed().inTimeZone(timeZone)).build();

The cron expression is:

0 0 10 * * ?

But the job start running at 10:00 AM (and ignore the start time). If i'm looking at qrtz_triggers table in the db I see that the start_time is indeed 9:30 but next_fire_time is 10:00.

What am I doing wrong here?

Était-ce utile?

La solution

The start and end times are the window in which the cron schedule is active. They do not specify the first and final time a trigger will be fired.

For example a schedule that fires every hour with a start time of 9:30am and end time of 6:30pm will fire on the hour during this period.

In your case this is not relevant as your cron schedule is once per day at 10am and this falls within the start and end time window.

If you want to fire a job at both 9:30am and 10am each day then the easiest way is to create two cron triggers that both invoke the same job.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top