org.springframework.scheduling.annotation

Annotation Type Scheduled



  • @Target(value={METHOD,ANNOTATION_TYPE})
     @Retention(value=RUNTIME)
     @Documented
     @Repeatable(value=Schedules.class)
    public @interface Scheduled
    An annotation that marks a method to be scheduled. Exactly one of the cron(), fixedDelay(), or fixedRate() attributes must be specified.

    The annotated method must expect no arguments. It will typically have a void return type; if not, the returned value will be ignored when called through the scheduler.

    Processing of @Scheduled annotations is performed by registering a ScheduledAnnotationBeanPostProcessor. This can be done manually or, more conveniently, through the <task:annotation-driven/> element or @EnableScheduling annotation.

    This annotation may be used as a meta-annotation to create custom composed annotations with attribute overrides.

    Since:
    3.0
    Author:
    Mark Fisher, Juergen Hoeller, Dave Syer, Chris Beams
    See Also:
    EnableScheduling, ScheduledAnnotationBeanPostProcessor, Schedules
    • Field Summary

      Fields 
      Modifier and Type Fields and Description
      static java.lang.String CRON_DISABLED
      A special cron expression value that indicates a disabled trigger: "-".
    • Optional Element Summary

      Optional Elements 
      Modifier and Type Optional Element and Description
      java.lang.String cron
      A cron-like expression, extending the usual UN*X definition to include triggers on the second as well as minute, hour, day of month, month and day of week.
      long fixedDelay
      Execute the annotated method with a fixed period in milliseconds between the end of the last invocation and the start of the next.
      java.lang.String fixedDelayString
      Execute the annotated method with a fixed period in milliseconds between the end of the last invocation and the start of the next.
      long fixedRate
      Execute the annotated method with a fixed period in milliseconds between invocations.
      java.lang.String fixedRateString
      Execute the annotated method with a fixed period in milliseconds between invocations.
      long initialDelay
      Number of milliseconds to delay before the first execution of a fixedRate() or fixedDelay() task.
      java.lang.String initialDelayString
      Number of milliseconds to delay before the first execution of a fixedRate() or fixedDelay() task.
      java.lang.String zone
      A time zone for which the cron expression will be resolved.
    • Field Detail

      • CRON_DISABLED

        public static final java.lang.String CRON_DISABLED
        A special cron expression value that indicates a disabled trigger: "-".

        This is primarily meant for use with ${...} placeholders, allowing for external disabling of corresponding scheduled methods.

        Since:
        5.1
    • Element Detail

      • cron

        public abstract java.lang.String cron
        A cron-like expression, extending the usual UN*X definition to include triggers on the second as well as minute, hour, day of month, month and day of week.

        E.g. "0 * * * * MON-FRI" means once per minute on weekdays (at the top of the minute - the 0th second).

        The special value "-" indicates a disabled cron trigger, primarily meant for externally specified values resolved by a ${...} placeholder.

        Returns:
        an expression that can be parsed to a cron schedule
        See Also:
        CronSequenceGenerator
        Default:
        ""
      • zone

        public abstract java.lang.String zone
        A time zone for which the cron expression will be resolved. By default, this attribute is the empty String (i.e. the server's local time zone will be used).
        Returns:
        a zone id accepted by TimeZone.getTimeZone(String), or an empty String to indicate the server's default time zone
        Since:
        4.0
        See Also:
        CronTrigger.CronTrigger(String, java.util.TimeZone), TimeZone
        Default:
        ""
      • fixedDelay

        public abstract long fixedDelay
        Execute the annotated method with a fixed period in milliseconds between the end of the last invocation and the start of the next.
        Returns:
        the delay in milliseconds
        Default:
        -1L
      • fixedDelayString

        public abstract java.lang.String fixedDelayString
        Execute the annotated method with a fixed period in milliseconds between the end of the last invocation and the start of the next.
        Returns:
        the delay in milliseconds as a String value, e.g. a placeholder or a java.time.Duration compliant value
        Since:
        3.2.2
        Default:
        ""
      • fixedRate

        public abstract long fixedRate
        Execute the annotated method with a fixed period in milliseconds between invocations.
        Returns:
        the period in milliseconds
        Default:
        -1L
      • fixedRateString

        public abstract java.lang.String fixedRateString
        Execute the annotated method with a fixed period in milliseconds between invocations.
        Returns:
        the period in milliseconds as a String value, e.g. a placeholder or a java.time.Duration compliant value
        Since:
        3.2.2
        Default:
        ""
      • initialDelay

        public abstract long initialDelay
        Number of milliseconds to delay before the first execution of a fixedRate() or fixedDelay() task.
        Returns:
        the initial delay in milliseconds
        Since:
        3.2
        Default:
        -1L
      • initialDelayString

        public abstract java.lang.String initialDelayString
        Number of milliseconds to delay before the first execution of a fixedRate() or fixedDelay() task.
        Returns:
        the initial delay in milliseconds as a String value, e.g. a placeholder or a java.time.Duration compliant value
        Since:
        3.2.2
        Default:
        ""