您的位置:首页 > 其它

把某个线程interrupt()后,竟然还继续执行!那这个方法究竟有啥用呢?

2014-04-24 21:14 423 查看
import java.io.IOException;
public class Test {

public static void main(String[] args) throws InterruptedException, IOException {
ThreadInterrupt t = new ThreadInterrupt();
Thread thread = new Thread(t);
thread.start();
Thread.sleep(5000);
//5秒后thread被打断
thread.interrupt();
System.out.println("线程退出运行!");
}

}

public class ThreadInterrupt implements Runnable{
public void run() {
for(int i=0;i<500;i++){
System.out.println("i am a running thread"+(i));
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
System.out.println("睡眠被打断!");
}
}
}
}
interrupt()方法困惑?












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