Currently I have this :
@Scheduled(fixedRate=5000)
public void getSchedule(){
System.out.println("in scheduled job");
}
I could change this to use a reference to a property
@Scheduled(fixedRate=${myRate})
public void getSchedule(){
System.out.println("in scheduled job");
}
However I need to use a value obtained programmatically so the schedule can be changed without redeploying the app. What is the best way? I realize using annotations may not be possible...
you can manage restarting scheduling using TaskScheduler and ScheduledFuture :
interface for start stop :
now you can stop and start again (restarting) Scheduling using @Autowired SchedulerObjectInterface
Also you can use this simple approach:
refreshTickNumber
is fully configurable at runtime and can be used with@Value
annotation.Using a
Trigger
you can calculate the next execution time on the fly.Something like this should do the trick (adapted from the Javadoc for
@EnableScheduling
):