为什么我写的没有被中断?
来源:5-3 如何停止线程

JF1sh
2020-04-21
public class StopThreadForInterrupted implements Runnable{
@Override
public void run() {
int num = 0;
while (!Thread.currentThread().isInterrupted() && num <= Integer.MAX_VALUE/2 ){
if(num % 10000 ==0){
System.out.println(num + ":是100的倍数");
}
num++;
}
System.out.println("结束");
}
public static void main(String[] args) throws InterruptedException {
Thread thread = new Thread(new StopThreadForInterrupted( ));
thread.start();
Thread.sleep(1000);
thread.interrupted();
}
}
写回答
2回答
-
悟空
2020-04-21
中断的方法是interrupt。
122020-04-21 -
悟空
2020-04-21
你仔细对比一下我写的代码吧。
00
相似问题