Class CronTrigger
- All Implemented Interfaces:
Trigger
Trigger implementation for cron expressions. Wraps a
CronExpression which parses according to common crontab conventions.
Supports a Quartz day-of-month/week field with an L/# expression. Follows common cron conventions in every other respect, including 0-6 for SUN-SAT (plus 7 for SUN as well). Note that Quartz deviates from the day-of-week convention in cron through 1-7 for SUN-SAT whereas Spring strictly follows cron even in combination with the optional Quartz-specific L/# expressions.
- Since:
- 3.0
- Author:
- Juergen Hoeller, Arjen Poutsma
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCronTrigger(String expression) Build aCronTriggerfrom the pattern provided in the default time zone.CronTrigger(String expression, ZoneId zoneId) Build aCronTriggerfrom the pattern provided in the given time zone, with the same lenient execution asCronTrigger(String).CronTrigger(String expression, TimeZone timeZone) Build aCronTriggerfrom the pattern provided in the given time zone, with the same lenient execution asCronTrigger(String). -
Method Summary
Modifier and TypeMethodDescriptionbooleanstatic CronTriggerforFixedExecution(String expression) Create aCronTriggerfor fixed execution, to be rescheduled after every task based on the last scheduled time.static CronTriggerforLenientExecution(String expression) Create aCronTriggerfor lenient execution, to be rescheduled after every task based on the completion time.Return the cron pattern that this trigger has been built with.inthashCode()nextExecution(TriggerContext triggerContext) Determine the next execution time according to the given trigger context.static CronTriggerresumeFixedExecution(String expression, Instant resumptionTimestamp) Create aCronTriggerfor fixed execution, to be rescheduled after every task based on the last scheduled time.static CronTriggerresumeLenientExecution(String expression, Instant resumptionTimestamp) Create aCronTriggerfor lenient execution, to be rescheduled after every task based on the completion time.toString()Methods inherited from interface Trigger
nextExecutionTime
-
Constructor Details
-
CronTrigger
Build aCronTriggerfrom the pattern provided in the default time zone.This is equivalent to the
forLenientExecution(String)factory method. Original trigger firings may be skipped if the previous task is still running; if this is not desirable, considerforFixedExecution(String).- Parameters:
expression- a space-separated list of time fields, following cron expression conventions- See Also:
-
CronTrigger
Build aCronTriggerfrom the pattern provided in the given time zone, with the same lenient execution asCronTrigger(String).Note that such explicit time zone customization is usually not necessary, using
TaskScheduler.getClock()instead.- Parameters:
expression- a space-separated list of time fields, following cron expression conventionstimeZone- a time zone in which the trigger times will be generated
-
CronTrigger
Build aCronTriggerfrom the pattern provided in the given time zone, with the same lenient execution asCronTrigger(String).Note that such explicit time zone customization is usually not necessary, using
TaskScheduler.getClock()instead.- Parameters:
expression- a space-separated list of time fields, following cron expression conventionszoneId- a time zone in which the trigger times will be generated- Since:
- 5.3
- See Also:
-
-
Method Details
-
getExpression
Return the cron pattern that this trigger has been built with. -
nextExecution
Determine the next execution time according to the given trigger context.Next execution times are calculated based on the completion time of the previous execution; therefore, overlapping executions won't occur.
- Specified by:
nextExecutionin interfaceTrigger- Parameters:
triggerContext- context object encapsulating last execution times and last completion time- Returns:
- the next execution time as defined by the trigger,
or
nullif the trigger won't fire anymore
-
equals
-
hashCode
-
toString
-
forLenientExecution
Create aCronTriggerfor lenient execution, to be rescheduled after every task based on the completion time.This variant does not make up for missed trigger firings if the associated task has taken too long. As a consequence, original trigger firings may be skipped if the previous task is still running.
This is equivalent to the regular
CronTriggerconstructor. Note that lenient execution is scheduler-dependent: it may skip trigger firings with long-running tasks on a thread pool while executing atforFixedExecution(String)-like precision with new threads per task.- Parameters:
expression- a space-separated list of time fields, following cron expression conventions- Since:
- 6.1.3
- See Also:
-
resumeLenientExecution
Create aCronTriggerfor lenient execution, to be rescheduled after every task based on the completion time.This variant does not make up for missed trigger firings if the associated task has taken too long. As a consequence, original trigger firings may be skipped if the previous task is still running.
- Parameters:
expression- a space-separated list of time fields, following cron expression conventionsresumptionTimestamp- the timestamp to resume from (the last-known completion timestamp), with the new trigger calculated from there and possibly immediately firing (but only once, every subsequent calculation will start from the completion time of that first resumed trigger)- Since:
- 6.1.3
- See Also:
-
forFixedExecution
Create aCronTriggerfor fixed execution, to be rescheduled after every task based on the last scheduled time.This variant makes up for missed trigger firings if the associated task has taken too long, scheduling a task for every original trigger firing. Such follow-up tasks may execute late but will never be skipped.
Immediate versus late execution in case of long-running tasks may be scheduler-dependent but the guarantee to never skip a task is portable.
- Parameters:
expression- a space-separated list of time fields, following cron expression conventions- Since:
- 6.1.3
- See Also:
-
resumeFixedExecution
Create aCronTriggerfor fixed execution, to be rescheduled after every task based on the last scheduled time.This variant makes up for missed trigger firings if the associated task has taken too long, scheduling a task for every original trigger firing. Such follow-up tasks may execute late but will never be skipped.
- Parameters:
expression- a space-separated list of time fields, following cron expression conventionsresumptionTimestamp- the timestamp to resume from (the last-known scheduled timestamp), with every trigger in-between immediately firing to make up for every execution that would have happened in the meantime- Since:
- 6.1.3
- See Also:
-