![](/img/trans.png)
[英]Java Wait for thread(in another class) to finish before executing code in activity
[英]wait executing block of code for thread dies
我想要的所有代碼塊等待另一個線程死亡,其中該線程不是事件線程
我相信這是Thread.join()
方法的用途:
公共最終void join()拋出InterruptedException
等待該線程死亡。
可以在此處使用java.util.concurrent.CountDownLatch
。
據我了解,看起來您希望在線程死后執行一段代碼,但是您不希望Thread.join()阻塞當前線程嗎? 然后在另一個線程中執行整個操作:
new Thread() {
public void run() {
someThread.join(); // someThread is the thread that you're waiting to die
// your block of code
}
}.start();
這將在someThread死后執行代碼,但不會掛起當前線程。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.