作者recorriendo (孟新)
看板java
标题[问题] Thread interrupt的问题
时间Sun Jul 22 06:20:50 2012
大家好 小弟最近在学Threading
关於interrupt 我查了很多地方都没写得很清楚
所以我写了下面这个程式
public class ThreadPlay extends Thread {
@Override
public void run() {
System.out.println(isInterrupted());
this.interrupt();
System.out.println(isInterrupted());
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(isInterrupted());
}
public static void main(String[] args) {
ThreadPlay thr = new ThreadPlay();
thr.start();
}
}
执行後 三行println印出来分别是false, true, false
所以说 interrupt之後isInterrupted()会传回true
但如果有InterruptedException 之後 又会被改回false?
请问这是Java原本的设定 还是跟我自己编译器的解读有关? 谢谢各位解答
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 128.12.247.107
※ 编辑: recorriendo 来自: 128.12.247.107 (07/22 06:24)