您的位置:首页 > 其它

线程中断

2014-07-03 20:41 134 查看
ublic class Main {

public static void main(String[] args) throws InterruptedException {
Test test=new Test();
test.start();
Thread.sleep(2000);
//中断线程
test.interrupt();
}

static class Test extends Thread{

@Override
public void run() {
for (int i = 0; i <Integer.MAX_VALUE; i++) {
System.out.println("---------->i");

//中断线程
if (isInterrupted()) {
System.out.println("........中断线程");
return ;
}

/*if (Thread.interrupted()) {

try {

throw new InterruptedException();

} catch (InterruptedException e) {
System.out.println("........线程中断");
}

}*/
}

}
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: