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("........线程中断");
}
}*/
}
}
}
}
线程中断
最新推荐文章于 2023-10-25 10:55:50 发布