作者issuemylove (skill)
看板AndroidDev
标题[问题] thread 终止一问
时间Wed Jan 23 12:26:04 2013
看到网路上有关终止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
1F:→ popcorny:看需求吧..还有wait通常搭配的是notify.. interrupt会有 01/23 13:18
2F:→ popcorny:exception 01/23 13:18