Question

Is there any way to interrupt a Future without cancelling it?

java doc API:

boolean cancel (boolean mayInterruptIfRunning)

Attempts to cancel execution of this task. This attempt will fail if the task has already completed, has already been cancelled, or could not be cancelled for some other reason. If successful, and this task has not started when cancel is called, this task should never run. If the task has already started, then the mayInterruptIfRunning parameter determines whether the thread executing this task should be interrupted in an attempt to stop the task.

To capture the interrupt, we have to properly catch the Interrupted Exception or check the isInterrupted() method within the Runnable / Callable method.

But there is no way to interrupt a running Future using the Future interface

Since all the threads are in the Executor Service pool, no one can do thread.interrupt(). Is that why it has been assumed that any interrupt will come only when a Future is cancelled or a Thread Pool is terminating?

I am trying to understand why there is not a interrupt method in the Future interface. Any help will be greatly appreciated

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top