863394 wrote:Get a reference to the Thread and call stop(). BTW it generally a bad idea, but it can be done.
Is there any way to stop the future Object task after a certain time out irrespective of its current state?
I want to terminate the thread execution and make the thread pick another task once if it is timed out.You should change your task so it is interruptible.
One way is to interrupt the thread which is handling the future object task and then stop the thread.Future.cancel(true) interrupts the thread if it has started. Stopping the Thread is likely to be harder to get right than making your task interruptible. (possibly impossible)
Is there any other way that I can cancel a future Object task directly without dealing with the thread handling this future object task.No. cancel() is the only way to cancel.
The callable object needs to check whether it has been interrupted (periodically call Thread.interrupted() to see if it should exit)