Your assumption seems to be wrong, shutdown()
should only act on the outer executor. It does not shut down any other executors.
Here's a small example based on your code:
ExecutorService e1 = Executors.newFixedThreadPool(20);
final ExecutorService e2 = Executors.newFixedThreadPool(2);
e1.execute(new Runnable() {
public void run() {
System.out.println("e1 started");
e2.execute(new Runnable() {
public void run() {
System.out.println("e2 started");
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
}
System.out.println("e2 completed");
}
});
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
}
});
e1.shutdown();
System.out.println("e1 shut down signal send");
e1.awaitTermination(30, TimeUnit.MINUTES);
System.out.println("e1 terminated");
e2.awaitTermination(30, TimeUnit.MINUTES);
System.out.println("e2 terminated");
The application won't terminate, it blocks on e2.awaitTermination
and in the output it also shows that e2
never got a shut down signal:
e1 started
e1 shut down signal send
e2 started
e1 terminated
e2 completed
If mailExecutor
really does shut down, I think there is something else going on that is not shown in your code. As the basic structure of your code looks now, you are running a single task and immediately shut down the executer, which could mean you may don't even need the blastExecutor
.