→ Chikei: Object.wait/notify 05/29 14:02
→ LaPass: 試不出來,叫了notify notifyAll 可是wait都沒醒 05/29 15:03
private class DrawRunnable implements Runnable{
void update(){
last=System.currentTimeMillis();
synchronized (this){
notifyAll();
}
}
public void run() {
while (run) {
try {
//dosomething
synchronized (this) {
wait(); // <= 卡在這裡,其他執行序叫了update也沒醒
}
Log.d("F23ko", "DrawRunnable STEP UNLOCK");
} catch (InterruptedException e) {
}
}
}
}
※ 編輯: LaPass (125.227.87.115), 05/29/2015 15:10:55
→ LaPass: 是在android上,不過這應該不會有影響才對 05/29 15:15
→ LaPass: 用 thread.interrupt() 可以叫的醒,不過覺得用那種方式去 05/29 15:22
→ LaPass: 叫執行序不太好... 05/29 15:22
→ LaPass: 因為可能作到一半(非block狀態下)被打斷 05/29 15:26
推 Frozenmouse: 你兩個Thread拿到的this是一樣的嗎? 05/29 17:25
推 Frozenmouse: 如果兩條thread操作的DrawRunnable是同一個,這code 05/29 17:37
→ Frozenmouse: 看起來沒問題…orz 05/29 17:37
→ LaPass: 我確認一下..... 05/29 18:18
→ LaPass: 對不起,是我耍蠢了 m(_ _)m 05/29 19:22