what happens to running/blocked runnables when executorservice is shutdown()
- by prmatta
I posted a question about a thread pattern today, and almost everyone suggested that I look into the ExecutorService.
While I was looking into the ExecutorService, I think I am missing something. What happens if the service has a running or blocked threads, and someone calls ExecutorService.shutdown(). What happens to threads that are running or blocked?
Does the ExecutorService wait for those threads to complete before it terminates?
The reason I ask this is because a long time ago when I used to dabble in Java, they deprecated Thread.stop(), and I remember the right way of stopping a thread was to use sempahores and extend Thread when necessary:
public void run () {
while (!this.exit) {
try {
block();
//do something
} catch (InterruptedException ie) {
}
}
}
public void stop () {
this.exit = true;
if (this.thread != null) {
this.thread.interrupt();
this.thread = null;
}
}
How does ExecutorService handle running threads?