Configuring Scheduled Tasks with Annotation Metadata
If you wish to make your application’s tasks configurable then you can use annotation metadata and property placeholder configuration to do so. For example:
Allow tasks to be configured
@Scheduled( fixedRate = "${my.task.rate:5m}",
initialDelay = "${my.task.delay:1m}" )
void configuredTask() {
System.out.println("Executing configuredTask()");
}
Allow tasks to be configured
@Scheduled( fixedRate = "\${my.task.rate:5m}",
initialDelay = "\${my.task.delay:1m}" )
void configuredTask() {
System.out.println("Executing configuredTask()")
}
Allow tasks to be configured
@Scheduled(fixedRate = "\${my.task.rate:5m}",
initialDelay = "\${my.task.delay:1m}")
internal fun configuredTask() {
println("Executing configuredTask()")
}
The above example allows the task execution frequency to be configured with the property my.task.rate
and the initial delay to be configured with the property my.task.delay
.