InvokeAll timeout interrupt

Viewed 1930

Question:

How do I make a series of threads that have timed out with invokeAll stop execution.

Background:

I have a list of callables I want to wait to complete. However, if they don't complete within a set time (say a second) I want to cancel them. This seems easy enough with

executor.invokeAll(callables, 1000l, TimeUnit.MILLISECONDS);

So after a second it will time out just fine and I can go on with my day. However in the background the threads are still active and potentially executing some pieces of code. Essentially they are not interrupted which I do not want to happen - I want the threads to stop executing.

Is there any way to use the futures list returned to stop the threads after invokeAll has hit its timeout?

2 Answers
Related