I am using a single ScheduledThreadPoolExecutor
to manage multiple tasks and would like to add the option to stop them.
I understand the difference between shutdown and shutdownNow on a regular executor service, and am interested in understanding how it will affect tasks in a ScheduledThreadPoolExecutor
- where tasks are also scheduled to be run on a regular interval.
Given a running ScheduledThreadPoolExecutor
that has both running tasks, one time tasks schedled to be run in the future, and tasks that are scheduled to be run in a constant interval (once every X minutes).
What will be the best way to implement the following "commands" :
- Stop everything now. Stop all running tasks immediately, Do not run any tasks that were already scheduled but did not yet start.
- Currently running threads can be completed if required. Do not run any tasks that were already scheduled but did not yet start.