看板 AndroidDev 關於我們 聯絡資訊
看到網路上有關終止thread運行的方法 比較常用的是 (1) 設定一個變數好讓 thread 從這個變數去判斷 例如: Thread{ boolean flag = fase; run(){ while(!flag){ ... } } } Thread t = new Thread(); t.start(); 或是 (2) thread 在 sleep, wait, join 的狀態下 可以呼叫 interrupt() 來終止 thread 可是好像都沒有看到下面的方式去把一個thread給終止 ? Thread t = new Thread ... ; try{ t.wait(); }catch(...){} t.interrupt(); 這樣看似沒問題呀? 想要終止一個thread 的時候就呼叫 wait + interrupt 可是為何沒看到過大家這樣用呢? 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 118.163.3.187
popcorny:看需求吧..還有wait通常搭配的是notify.. interrupt會有 01/23 13:18
popcorny:exception 01/23 13:18