首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

java查看线程间断状态

2012-08-27 
java查看线程中断状态public class InterruptCheck {public static void main(String[] args) {Thread t

java查看线程中断状态
public class InterruptCheck {
public static void main(String[] args) {
Thread t = Thread.currentThread();
System.out.println("A:t.isInterrupted()="+t.isInterrupted());
t.interrupt();
System.out.println("B:t.isInterrupted()="+t.isInterrupted());
System.out.println("C:t.isInterrupted()="+t.isInterrupted());
try {
Thread.sleep(1000);
System.out.println("线程没有被中断");
} catch (InterruptedException x) {
System.out.println("线程被中断");
}
//因为sleep抛出了异常,所以它清除了中断标志
System.out.println("D:t.isInterrupted()="+t.isInterrupted());

}
}

热点排行