把某个线程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()方法困惑?
相关文章推荐
- java进阶 线程池 join用法总结:thread4.join();方法,就表明thread4.join();这个线程受到贵客待遇,直到这个线程执行完,被插入这个方法的载体线程才可以执行。
- 多线程中主线程等待所有子线程执行完再继续执行的解决方法
- 多线程中主线程等待所有子线程执行完再继续执行的解决方法
- 有三个线程T1,T2,T3,下面方法可以确保它们按顺序执行的有()该线程继续执行
- Java线程暂停一段时间之后继续执行的实现方法
- 方法阻塞,方法一直阻塞,意味着这个程序卡在这里,一直不向下运行。知道这个阻塞方法执行完毕,有返回值。程序才继续向下执行
- “对不起,您安装的不是正版应用,安装程序无法继续执行 discuz”解决方法
- java 线程的中断interrupt方法
- cocos的cclayer有onEnter()方法,这个在啥时候执行啊?
- C#中添加三个线程同时启动执行某一方法,并依次调用某方法中的循环打印输。
- (53)停止线程,interrupt()方法+标记修改
- 每隔一段时间自动执行一次某个方法(使用线程)[C#]
- Discuz! X2.5安装模板插件出现:对不起,您安装的不是正版应用,安装程序无法继续执行的解决方法
- C#中Join()方法实现线程的顺序执行
- 停止Java线程,小心interrupt()方法
- Java调优—Btrace监控Java线程/方法执行参数、执行时间(Windows)
- mysql 批处理文件出错后继续执行的实现方法
- java线程之sleep、interrupt方法
- Java学习笔记78. 线程的中断入门 —— interrupt方法
- 使用interrupt()方法和isInterrupted()方法实现了线程