<span style= "font-size:18px;" >package thread.java.test;/** * Practice here is the thread interrupt * THREAD.INTERRUPT () to set the interrupt state is true when one thread is running and another thread can invoke the interrupt of another * thread () method to interrupt him * THREAD.ISINTERRUPT () to get the interrupt state of the thread * thread.interrupted () This is a static method used to get the interrupt state, and to clear the interrupt state, * It gets the value before the purge, call two consecutive times, The second time will definitely return false * @author Hello * @version jdk1.8.45 * @since 2015-07-25 * */public class Sleepinterrupt implements Runnable { public void Run () {try {System.out.println ("in the Run () method-this thread sleeps for 10 seconds"); Thread.Sleep (10000); System.out.println ("In the Run () method-Continue running");} catch (Interruptedexception e) {e.printstacktrace ();} System.out.println ("In the Run () method--continue to complete after hibernation"); System.out.println ("In the Run () method-Normal Exit");} public static void Main (string[] args) {sleepinterrupt si=new sleepinterrupt (); Thread t=new thread (SI), T.start (), try {thread.sleep (),} catch (Interruptedexception e) {e.printstacktrace ();} System.out.println ("in the Main () method-interrupts other threads"); T.interrupt (); SYSTEM.OUT.PRINTLN ("in Main ()--Exit");}} </span>
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Interrupt Learning for Java threads