Annotation Type Scheduled
-
@Target(METHOD) @Retention(RUNTIME) @Repeatable(Schedules.class) public @interface Scheduled
Identifies a method of a bean class that is automatically scheduled and invoked by the container.A scheduled method is a non-abstract non-private method of a bean class. It may be either static or non-static.
The schedule is defined either by
cron()or byevery()attribute. If both are specified, the cron expression takes precedence.@ApplicationScoped class MyService { @Scheduled(cron = "0/5 * * * * ?") void check() { // do something important every 5 seconds } }The annotated method must returnvoid,java.util.concurrent.CompletionStage<Void>orio.smallrye.mutiny.Uni<Void>and either declare no parameters or one parameter of typeScheduledExecution.By default, a scheduled method is executed on the main executor for blocking tasks. However, a scheduled method that returns
java.util.concurrent.CompletionStage<Void>orio.smallrye.mutiny.Uni<Void>, or is annotated withNonBlockingis executed on the event loop.- See Also:
ScheduledExecution
-
-
Optional Element Summary
Optional Elements Modifier and Type Optional Element Description Scheduled.ConcurrentExecutionconcurrentExecutionSpecify the strategy to handle concurrent execution of a scheduled method.StringcronDefines a cron-like expression.longdelayDelays the time the trigger should start at.StringdelayedDefines a period after which the trigger should start.TimeUnitdelayUnitStringeveryDefines a period between invocations.StringidentityOptionally defines a unique identifier for this job.StringoverdueGracePeriodDefines a period after which the job is considered overdue.Class<? extends Scheduled.SkipPredicate>skipExecutionIfSpecify the bean class that can be used to skip any execution of a scheduled method.
-
-
-
Element Detail
-
identity
String identity
Optionally defines a unique identifier for this job.The value can be a property expression. In this case, the scheduler attempts to use the configured value instead:
@Scheduled(identity = "${myJob.identity}"). Additionally, the property expression can specify a default value:@Scheduled(identity = "${myJob.identity:defaultIdentity}").If the value is not provided then a unique id is generated.
- Returns:
- the unique identity of the schedule
- Default:
- ""
-
-
-
cron
String cron
Defines a cron-like expression. For example "0 15 10 * * ?" fires at 10:15am every day.The value can be a property expression. In this case, the scheduler attempts to use the configured value instead:
@Scheduled(cron = "${myJob.cronExpression}"). Additionally, the property expression can specify a default value:@Scheduled(cron = "${myJob.cronExpression:0/2 * * * * ?}").Furthermore, two special constants can be used to disable the scheduled method:
offanddisabled. For example,@Scheduled(cron="${myJob.cronExpression:off}")means that if the property is undefined then the method is never executed.- Returns:
- the cron-like expression
- Default:
- ""
-
-
-
every
String every
Defines a period between invocations.The value is parsed with
Duration.parse(CharSequence). However, if an expression starts with a digit, "PT" prefix is added automatically, so for example,15mcan be used instead ofPT15Mand is parsed as "15 minutes". Note that the absolute value of the value is always used.The value can be a property expression. In this case, the scheduler attempts to use the configured value instead:
@Scheduled(every = "${myJob.everyExpression}"). Additionally, the property expression can specify a default value:@Scheduled(every = "${myJob.everyExpression:5m}").Furthermore, two special constants can be used to disable the scheduled method:
offanddisabled. For example,@Scheduled(every="${myJob.everyExpression:off}")means that if the property is undefined then the method is never executed.- Returns:
- the period expression based on the ISO-8601 duration format
PnDTnHnMn.nS
- Default:
- ""
-
-
-
delayed
String delayed
Defines a period after which the trigger should start. It's an alternative todelay(). Ifdelay()is set to a value greater than zero the value ofdelayed()is ignored.The value is parsed with
Duration.parse(CharSequence). However, if an expression starts with a digit, "PT" prefix is added automatically, so for example,15scan be used instead ofPT15Sand is parsed as "15 seconds". Note that the absolute value of the value is always used.The value can be a property expression. In this case, the scheduler attempts to use the configured value instead:
@Scheduled(delayed = "${myJob.delayedExpression}"). Additionally, the property expression can specify a default value:@Scheduled(delayed = "${myJob.delayedExpression:5m}").- Returns:
- the period expression based on the ISO-8601 duration format
PnDTnHnMn.nS
- Default:
- ""
-
-
-
concurrentExecution
Scheduled.ConcurrentExecution concurrentExecution
Specify the strategy to handle concurrent execution of a scheduled method. By default, a scheduled method can be executed concurrently.- Returns:
- the concurrent execution strategy
- Default:
- io.quarkus.scheduler.Scheduled.ConcurrentExecution.PROCEED
-
-
-
skipExecutionIf
Class<? extends Scheduled.SkipPredicate> skipExecutionIf
Specify the bean class that can be used to skip any execution of a scheduled method.There must be exactly one bean that has the specified class in its set of bean types, otherwise the build fails. Furthermore, the scope of the bean must be active during execution. If the scope is
Dependentthen the bean instance belongs exclusively to the specific scheduled method and is destroyed when the application is shut down.- Returns:
- the bean class
- Default:
- io.quarkus.scheduler.Scheduled.Never.class
-
-
-
overdueGracePeriod
String overdueGracePeriod
Defines a period after which the job is considered overdue.The value is parsed with
Duration.parse(CharSequence). However, if an expression starts with a digit, "PT" prefix is added automatically, so for example,15mcan be used instead ofPT15Mand is parsed as "15 minutes". Note that the absolute value of the value is always used.The value can be a property expression. In this case, the scheduler attempts to use the configured value instead:
@Scheduled(overdueGracePeriod = "${myJob.overdueExpression}"). Additionally, the property expression can specify a default value:@Scheduled(overdueGracePeriod = "${myJob.overdueExpression:5m}").- Returns:
- the period expression based on the ISO-8601 duration format
PnDTnHnMn.nS
- Default:
- ""
-
-