I have around 10 jobs scheduled with @Scheduled and a hardcoded cron expression like this:
@Scheduled(cron = "* * 1 * * *")
public void testMethod(){
doSomething();
}
Now i want to be able to through the database update this cron expression and reschedule the specific job in runtime.
Does anyone knows how to do this?
Thanks
If you want to configure the scheduling of job at runtime, I don't think you can use the annotation @Scheduled
.
You can use your own scheduler instead from Spring documentation :
scheduler.schedule(task, new CronTrigger("0 15 9-17 * * MON-FRI"));
Then, if you want to change the configuration, you can cancel the scheduling and create a new one.
TaskScheduler
return a ScheduledFuture
that you should save somewhere and it can be cancelled with cancel(...)
method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With