References: Interrupt, isInterrupted, interrupted

public class ThreadTest { public static void main(String[] args) throws Exception{ Object A = new Object(); Thread t1 = new Thread() {@override public void run() {system.out.println (A) {system.out.println (A); long start = System.currentTimeMillis(); try { // A.wait(); Thread.sleep(10000); } Catch (InterruptedException e) {if wait, join, or sleep causes the thread to block, the external thread calls T1.interrupt () to set the termination status to true, and the thread is immediately awakened from the blocking state. Return false system.out. println(" Stop sleep, InterruptedException, sleep time: " + (System.currentTimeMillis() - start) + "ms"); } catch (Exception e){ System.out.println("====="+e.getMessage()); }}}}; t1.start(); Thread.sleep(3000); System.out.println("interrupt t1"); t1.interrupt(); }}Copy the code