Annotation Type Scheduled
@Target({METHOD,ANNOTATION_TYPE}) @Retention(RUNTIME) @Documented @Repeatable(Schedules.class) public @interface Scheduled
An annotation that marks a method to be scheduled. Exactly one of thecron(),fixedDelay(), orfixedRate()attributes must be specified.The annotated method must expect no arguments. It will typically have a
voidreturn type; if not, the returned value will be ignored when called through the scheduler.Processing of
@Scheduledannotations is performed by registering aScheduledAnnotationBeanPostProcessor. This can be done manually or, more conveniently, through the<task:annotation-driven/>element or @EnableSchedulingannotation.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
Optional Element Summary
Optional Elements Modifier and Type Optional Element Description StringcronA 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.longfixedDelayExecute the annotated method with a fixed period in milliseconds between the end of the last invocation and the start of the next.StringfixedDelayStringExecute the annotated method with a fixed period in milliseconds between the end of the last invocation and the start of the next.longfixedRateExecute the annotated method with a fixed period in milliseconds between invocations.StringfixedRateStringExecute the annotated method with a fixed period in milliseconds between invocations.longinitialDelayNumber of milliseconds to delay before the first execution of afixedRate()orfixedDelay()task.StringinitialDelayStringNumber of milliseconds to delay before the first execution of afixedRate()orfixedDelay()task.StringzoneA time zone for which the cron expression will be resolved.
Element Detail
cron
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).- Returns:
- an expression that can be parsed to a cron schedule
- See Also:
CronSequenceGenerator
- Default:
- ""
zone
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(String, java.util.TimeZone),TimeZone
- Default:
- ""
fixedDelay
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
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
- Since:
- 3.2.2
- Default:
- ""
fixedRate
long fixedRate
Execute the annotated method with a fixed period in milliseconds between invocations.- Returns:
- the period in milliseconds
- Default:
- -1L
fixedRateString
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
- Since:
- 3.2.2
- Default:
- ""
initialDelay
long initialDelay
Number of milliseconds to delay before the first execution of afixedRate()orfixedDelay()task.- Returns:
- the initial delay in milliseconds
- Since:
- 3.2
- Default:
- -1L
initialDelayString
String initialDelayString
Number of milliseconds to delay before the first execution of afixedRate()orfixedDelay()task.- Returns:
- the initial delay in milliseconds as a String value, e.g. a placeholder
- Since:
- 3.2.2
- Default:
- ""