I am trying to see whether it's possible to shutdownNow()
an ExecutorService which still has tasks in execution.
public static void main (String []args) throws InterruptedException
{
ExecutorService exSer = Executors.newFixedThreadPool(4);
List<ExecutorThing> lista = new ArrayList<>();
lista.add(new ExecutorThing());
lista.add(new ExecutorThing());
lista.add(new ExecutorThing());
lista.add(new ExecutorThing());
lista.add(new ExecutorThing());
List<Future<Object>> futureList = exSer.invokeAll(lista);
exSer.shutdownNow();
and class ExecutorThing is the following:
public class ExecutorThing implements Callable<Object>{
public Object call() {
while (!(Thread.currentThread().isInterrupted()))
for (int i=0;i<1;i++)
{
System.out.println(Thread.currentThread().getName());
}
return null;
}
}
I wonder why it never stops even though I check for the interrupt flag... and shutdownNow should terminate the tasks via interrupt()
.
Where am I wrong?
Thanks in advance.
PS in this question they offer as a solution the same thing I used, However it does not work to me. Maybe because I use invokeAll?
Thanks in advance.