{ Thread t1 = new Thread(() -> { while (true) { if(Thread.currentThread().isInterrupted()) { System.out.println(Thread.currentThread().getName()+"\t isInterrupted()被修改为true,程序停止"); System.out.println(Thread.currentThread().isInterrupted()); break; } System.out.println("t1 -----hello interrupt api"); } }, "t1"); t1.start();
System.out.println("-----t1的默认中断标志位:"+t1.isInterrupted());
try { TimeUnit.MILLISECONDS.sleep(20); } catch (InterruptedException e) { e.printStackTrace(); }
new Thread(() -> { t1.interrupt(); },"t2").start();
}
|