wait executing block of code for thread dies
all i want开发者_如何学Python block of code wait for another thread to die where this thread not event thread
I believe this is what Thread.join()
method is for:
public final void join() throws InterruptedException
Waits for this thread to die.
From what I've been able to understand, it looks like you want a block of code to be executed after some thread dies, but you don't want Thread.join() to block the current thread? Then execute the whole thing in a yet another thread:
new Thread() {
public void run() {
someThread.join(); // someThread is the thread that you're waiting to die
// your block of code
}
}.start();
This will execute the code after someThread dies, but won't suspend the current thread.
java.util.concurrent.CountDownLatch
can be used here.
精彩评论