Is there a way to start or stop a task scheduled using Spring Scheduled Tasks initialized using context file or @Scheduled annotation?
I would like to start the task when required and stop it when the task is no longer needed to be run.
If this is not possible, any alternative to injecting spring variables to a thread?
Best Answer
Here is an example of starting/stopping a scheduled method in Spring Boot. You can use such APIs:
http:localhost:8080/start - for starting scheduled method with fixed rate 5000 ms
http:localhost:8080/stop - for stopping scheduled method