看着幾款Android例子我看到線程使用join()方法暫停的趨勢:爲什麼的Thread.join通常用於停止線程的Android
編輯:請假設2個線程正確定義。編輯調用join()方法
public class MainUI extends Activity{
private GraphicsViewThread g;
private BackendDataViewThread b;
void onCreate(){
g = new GraphicsViewThread();
g.start();
b = new BackendDataViewThread();
b.start();
}
.
.
.
void pauseGame(){
try {
g.join();
}catch (InterruptedException e){
e.printStackTrace();
}
try {
b.join();
}catch (InterruptedException e){
e.printStackTrace();
}
GraphicsViewThread = null;
BackendDataViewThread = null;
}
}
- 哪個線程不GraphicsViewThread和BackendDataViewThread加盟?
- 使用join()需要什麼?我可以不立即將參考設置爲空嗎?
是否編譯過? –
@LewsTherin否,它不會編譯。我添加了一種僞代碼來顯示我在問什麼。對不起,如果我沒有說清楚 – user571099