The answer is quite simple, you just need to carefully read the Javadoc of invokeAll
:
Executes the given tasks, returning a list of Futures holding their status and results when all complete.
(emphasis mine).
In other words, your shutdownNow
never gets executed. I changed your code to this:
public class Test {
public static void main (String []args) throws InterruptedException
{
ExecutorService exSer = Executors.newFixedThreadPool(4);
exSer.submit(new ExecutorThing());
exSer.submit(new ExecutorThing());
exSer.submit(new ExecutorThing());
exSer.submit(new ExecutorThing());
exSer.shutdownNow();
}
}
class ExecutorThing implements Callable<Object> {
public Object call() throws InterruptedException {
while (!(currentThread().isInterrupted()))
System.out.println(currentThread().isInterrupted());
return null;
}
}
Not surprisingly, now it behaves just as you expect it to.