I'm using Grails 2.4.5 and plugin quartz 1.0.2. My job:
class NotWellpaidJob {
def staticaService
static triggers = {
cron name: 'cronTrigger',startDelay:3000, cronExpression: "0/20 58 16 ? * MON-FRI"
}
def execute() {
print new Date()
}
}
My output:
Thu Nov 19 16:58:00 CET 2015
Thu Nov 19 16:58:20 CET 2015
Thu Nov 19 16:58:40 CET 2015
Question:
Why startDelay doesn't delay first execution by 3 seconds and the first datetime isn't Thu Nov 19 16:58:03 CET 2015?
When you set a startDelay
on a cron trigger, the plugin is essentially modifying what's being passed to setStartTime
on the CronTriggerImpl class in Quartz.
From the Quartz documentation, the start time is defined as:
The time at which the trigger's scheduling should start. May or may not be the first actual fire time of the trigger, depending upon the type of trigger and the settings of the other properties of the trigger. However the first actual first time will not be before this date.
So what you're setting is actually the delay of when the job is scheduled, not when it is fired. This doesn't actually change the fire time of the first execution.