The following piece of code tries to accompolish this.
The code loops forever and checks if there are any pending requests to be processed. If there is any, it creat
You can either call shutdown()
on the ExecutorService
:
Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted.
or you can call shutdownNow()
:
Attempts to stop all actively executing tasks, halts the processing of waiting tasks, and returns a list of the tasks that were awaiting execution.
There are no guarantees beyond best-effort attempts to stop processing actively executing tasks. For example, typical implementations will cancel via Thread.interrupt(), so any task that fails to respond to interrupts may never terminate.
Which one you call depends how badly you want it to stop....