Class CronTrigger

java.lang.Object
org.springframework.scheduling.support.CronTrigger
All Implemented Interfaces:
Trigger

public class CronTrigger extends Object implements 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 Details

    • CronTrigger

      public CronTrigger(String expression)
      Build a CronTrigger from the pattern provided in the default time zone.
      Parameters:
      expression - a space-separated list of time fields, following cron expression conventions
    • CronTrigger

      public CronTrigger(String expression, TimeZone timeZone)
      Build a CronTrigger from the pattern provided in the given time zone.
      Parameters:
      expression - a space-separated list of time fields, following cron expression conventions
      timeZone - a time zone in which the trigger times will be generated
    • CronTrigger

      public CronTrigger(String expression, ZoneId zoneId)
      Build a CronTrigger from the pattern provided in the given time zone.
      Parameters:
      expression - a space-separated list of time fields, following cron expression conventions
      zoneId - a time zone in which the trigger times will be generated
      Since:
      5.3
      See Also:
  • Method Details

    • getExpression

      public String getExpression()
      Return the cron pattern that this trigger has been built with.
    • nextExecution

      public Instant nextExecution(TriggerContext triggerContext)
      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:
      nextExecution in interface Trigger
      Parameters:
      triggerContext - context object encapsulating last execution times and last completion time
      Returns:
      the next execution time as defined by the trigger, or null if the trigger won't fire anymore
    • equals

      public boolean equals(@Nullable Object other)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object