Java – spring scheduledtask – start / stop support?
Is there any way to start or stop tasks scheduled by spring scheduled tasks initialized with context files or @ scheduled annotations?
I want to start a task when I need it and stop it when I no longer need to run it
If this is not possible, what is an alternative to injecting any spring variables into the thread?
Solution
Stopping a registered @ scheduled bean is not a standard feature because it is available at org. Org springframework. scheduling. annotation. Access to them in the scheduled annotation bean post processor is private
If you need to manage the time they run, you need to register them programmatically (trigger task): see org springframework. scheduling. annotation. Documentation for the schedulingconfigurator At org springframework. scheduling. config. One of the triggertask types returns org springframework. scheduling. Trigger type method There you can manage the next execution time
In the case of programmatic registration, triggertasks can be beans