what happens to running/blocked runnables when executorservice is shutdown()
Posted
by prmatta
on Stack Overflow
See other posts from Stack Overflow
or by prmatta
Published on 2010-06-10T21:44:07Z
Indexed on
2010/06/10
21:52 UTC
Read the original article
Hit count: 283
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?
© Stack Overflow or respective owner