In question How to timeout a thread the suggested solution works with the ExecutorService
class, where one can submit a Runnable
object to be executed.
The ExecutorService
class provides the two methods shutdown
and shutdownNow
to stop the execution of all tasks. But the Java API says about 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."
I was wondering, if there is no way to perform a termination of a task WITH guarantee ?