@Target(value={METHOD,ANNOTATION_TYPE}) @Retention(value=RUNTIME) @Documented @Repeatable(value=Schedules.class) public @interface Scheduled
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/>
XML element or @EnableScheduling annotation.
This annotation can be used as a repeatable annotation. If several scheduled declarations are found on the same method, each of them will be processed independently, with a separate trigger firing for each of them. As a consequence, such co-located schedules may overlap and execute multiple times in parallel or in immediate succession.
This annotation may be used as a meta-annotation to create custom composed annotations with attribute overrides.
EnableScheduling,
ScheduledAnnotationBeanPostProcessor,
Schedules| Modifier and Type | Fields and Description |
|---|---|
static String |
CRON_DISABLED
A special cron expression value that indicates a disabled trigger: "-".
|
| Modifier and Type | Optional Element and Description |
|---|---|
String |
cron
A cron-like expression, extending the usual UN*X definition to include triggers
on the second, minute, hour, day of month, month, and day of week.
|
long |
fixedDelay
Execute the annotated method with a fixed period between the end of the
last invocation and the start of the next.
|
String |
fixedDelayString
Execute the annotated method with a fixed period between the end of the
last invocation and the start of the next.
|
long |
fixedRate
Execute the annotated method with a fixed period between invocations.
|
String |
fixedRateString
Execute the annotated method with a fixed period between invocations.
|
long |
initialDelay
Number of units of time to delay before the first execution of a
fixedRate() or fixedDelay() task. |
String |
initialDelayString
Number of units of time to delay before the first execution of a
fixedRate() or fixedDelay() task. |
TimeUnit |
timeUnit
The
TimeUnit to use for fixedDelay(), fixedDelayString(),
fixedRate(), fixedRateString(), initialDelay(), and
initialDelayString(). |
String |
zone
A time zone for which the cron expression will be resolved.
|
public static final String CRON_DISABLED
This is primarily meant for use with ${...} placeholders,
allowing for external disabling of corresponding scheduled methods.
ScheduledTaskRegistrar.CRON_DISABLEDpublic abstract String cron
For example, "0 * * * * MON-FRI" means once per minute on weekdays
(at the top of the minute - the 0th second).
The fields read from left to right are interpreted as follows.
The special value "-" indicates a disabled cron
trigger, primarily meant for externally specified values resolved by a
${...} placeholder.
CronExpression.parse(String)public abstract String zone
TimeZone.getTimeZone(String),
or an empty String to indicate the server's default time zoneCronTrigger(String, java.util.TimeZone),
TimeZonepublic abstract long fixedDelay
The time unit is milliseconds by default but can be overridden via
timeUnit().
public abstract String fixedDelayString
The time unit is milliseconds by default but can be overridden via
timeUnit().
This attribute variant supports Spring-style "${...}" placeholders as well as SpEL expressions.
java.time.Duration compliant valuefixedDelay()public abstract long fixedRate
The time unit is milliseconds by default but can be overridden via
timeUnit().
public abstract String fixedRateString
The time unit is milliseconds by default but can be overridden via
timeUnit().
This attribute variant supports Spring-style "${...}" placeholders as well as SpEL expressions.
java.time.Duration compliant valuefixedRate()public abstract long initialDelay
fixedRate() or fixedDelay() task.
The time unit is milliseconds by default but can be overridden via
timeUnit().
public abstract String initialDelayString
fixedRate() or fixedDelay() task.
The time unit is milliseconds by default but can be overridden via
timeUnit().
This attribute variant supports Spring-style "${...}" placeholders as well as SpEL expressions.
java.time.Duration compliant valueinitialDelay()public abstract TimeUnit timeUnit
TimeUnit to use for fixedDelay(), fixedDelayString(),
fixedRate(), fixedRateString(), initialDelay(), and
initialDelayString().
Defaults to TimeUnit.MILLISECONDS.
This attribute is ignored for cron expressions
and for Duration values supplied via fixedDelayString(),
fixedRateString(), or initialDelayString().
TimeUnit to use