interrupt不管用

chen_xiangguo chen_xiangguo 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
从java文档中得出:interrupt是中断线程,为此我做了个试验

public class Interrupt {
public static void main(String[] args) {
Runnable it=new InterruptTest();
Thread thread=new Thread(it);
thread.start();
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
thread.interrupt();
}
}
class InterruptTest implements Runnable {
@Override
public void run() {
int i=0;
while(true){
System.out.println(i++);
}
}

}

按理说2秒应该不打印才对,可是它一直打印个没完?
求高手
...全文
评论 3
收藏 已收藏
分享
返回顶部
chen_xiangguo
Java EE 67,535 成员 225,843 内容