Annotation Type Scheduled


@Retention(CLASS) @Target(METHOD) public @interface Scheduled

Runs this method of a bean on a schedule.

Exactly one of cron(), fixedRate() or fixedDelay() (or their String forms) must be given. The method takes no arguments.

A literal cron expression is parsed by the build, which writes its fields into the entry point as bit masks and refuses a malformed one: an expression nobody noticed was wrong otherwise fires never, or every second. One that reads configuration (${report.cron}) is parsed once at start-up instead.

The format is Spring's six fields -- second, minute, hour, day of month, month, day of week -- plus the @yearly, @monthly, @weekly, @daily and @hourly macros:

@Scheduled(cron = "0 */15 * * * MON-FRI")
public void refresh() { ... }

Several instances of one server each run every job. lock() makes a job run on one of them at a time, through a row in the database.

  • Element Details

    • cron

      String cron
      A cron expression, or ${key} to read one from configuration.
      Default:
      ""
    • zone

      String zone
      The time zone the cron expression is read in: a zone ID such as Europe/Berlin, a fixed offset such as +02:00, or UTC. Empty means UTC, which is what a server should keep its clock in anyway.
      Default:
      ""
    • fixedRate

      long fixedRate
      Milliseconds between the starts of consecutive runs.
      Default:
      -1L
    • fixedDelay

      long fixedDelay
      Milliseconds between the end of one run and the start of the next.
      Default:
      -1L
    • initialDelay

      long initialDelay
      Milliseconds before the first run of a fixed-rate or fixed-delay job.
      Default:
      -1L
    • fixedRateString

      String fixedRateString
      fixedRate() as text, which may read configuration.
      Default:
      ""
    • fixedDelayString

      String fixedDelayString
      fixedDelay() as text, which may read configuration.
      Default:
      ""
    • initialDelayString

      String initialDelayString
      initialDelay() as text, which may read configuration.
      Default:
      ""
    • thread

      ThreadKind thread
      Which kind of thread runs it.
      Default:
      PLATFORM
    • executor

      String executor
      The executor to run on. Empty means scheduling.
      Default:
      ""
    • lock

      String lock
      A lock name. When set, a run first claims the named row in the cn1_scheduler_lock table and is skipped if another instance holds it. Needs a database.
      Default:
      ""
    • lockAtMostFor

      long lockAtMostFor
      How long a claimed lock is held at most, in milliseconds, so an instance that dies mid-run does not hold it for good. Zero or less means ten minutes.
      Default:
      -1L