我有一個線程,我想知道何時等待方法正在運行。當線程運行如何檢查線程是否正在運行或等待在Android
這裏是我的代碼:
runnableClass rc = new runnableClass();
Object PauseTHR = new Object();
boolean pause = false;
public class runnableClass implements Runnable {
@Override
public void run() {
while(true) {
// here is my code,after my code i want to wait thread
// so i call onpause();
onpause();
synchronized (PauseTHR) {
while(pause) {
Log.i("while loop", "it goes over me");
try {
PauseTHR.wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
}
public void onpause() {
synchronized (PauseTHR) {
Log.i("synchronized", "it goes over me");
pause = true;
}
}
public void onresume() {
synchronized (PauseTHR) {
pause = false;
PauseTHR.notifyAll();
}
}
}
設置我的布爾(暫停)可變全球,但是當我檢查
if(pause == true)
rc.onresume();
了我的Runnable類的似乎不起作用,我的病情起作用 我該如何檢查我的線程何時等待,何時線程正在運行?
通過該方法返回的時間,信息是陳舊的。 –