Sleep does not allow a thread to release the synchronization lock it holds, nor does it prevent other threads from running during that time. An interrupt wakes up a sleeping or blocked thread.
Sleeping threads: Sleeping threads can make the current thread sleep for a period of time, during which time slots will not be allocated to threads. Until the end of this period, the thread runs again.
Thread wake-up: Thread wake-up can wake up threads that perform sleep operations or that perform wait operations or join operations. Threads need to specify a sleeping time. If interrput is performed on the thread, the thread can continue to run early. But for wake-up threads, a single thread can not wake itself up and can only wait for the end of the sleeping. If you want to wake yourself up in sleep, you can only wake yourself up by another thread.
Thread connection: Thread connection is an operation of inter-thread running scheduling, that is, threads need to wait for other threads to finish running before they can start, otherwise they continue to wait. There are two forms of thread connection: join (parameter) and join (parameter). In join (parameter) method, the parameter represents the waiting time in milliseconds. If this time is exceeded, the thread will continue to run regardless of whether the previous thread has finished executing or not. If the time is 0, it means waiting indefinitely. The join() method is equivalent to join(0), which means waiting indefinitely.
source program
Operational screenshotspackage core; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; public class TextSleepAndInterrupt extends Thread{ private DateFormat dateFormat=new SimpleDateFormat("HH-mm-ss:SSSS"); public void run(){ System.out.println(dateFormat.format(new Date())+" "+getName()+" Sleep for 3 seconds"); try { sleep(3000); //Thread hibernates for 3 seconds } catch (InterruptedException e) {//Capture wake-up anomalies System.out.println(getName()+dateFormat.format(new Date())+getName()+"Wake-up Abnormality"+e.getMessage()); } interrupt();//Wake-up threads, single thread itself can not wake up itself, can only wait for the end of sleep, can see the console output time. If you want to wake yourself up in sleep, you can only wake yourself up by another thread. System.out.println(dateFormat.format(new Date())+" Sleeping me, do you wake me up?"+isAlive()); } public void getUp(){ Thread.currentThread().interrupt();//Wake up the current thread while(true){ if(Thread.currentThread().isInterrupted()){//Determine whether the current thread is awakened System.out.println(dateFormat.format(new Date())+" Am I awakened at the moment?"+Thread.currentThread().isInterrupted()); try { Thread.currentThread().sleep(1); //Thread dormancy } catch (InterruptedException e) { System.out.println(dateFormat.format(new Date())+" "+getName()+" Wake-up Abnormality "+e.getMessage()+" "+Thread.currentThread().isInterrupted()); } System.out.println(dateFormat.format(new Date())+" Are you awakened after a deep sleep? "+Thread.currentThread().isInterrupted()); } } } public static void main(String[] args) { TextSleepAndInterrupt text=new TextSleepAndInterrupt(); text.start();//Start threads try { text.join(); //Thread connection threads need to wait for other threads to finish running before they can start } catch (InterruptedException e) {//Capture wake-up anomalies e.printStackTrace(); System.out.println(" Wake-up abnormality: "+e.getMessage()); } text.getUp(); } }

Source Procedure Interpretation
Source code feels like there is something wrong with the design. Here is the simplified and tidied code.
(1) The TextSleepAndInterrupt class must implement the run() method to inherit the Thread class. The sleep() method of the Thread class is called in the run() method to let the thread sleep (pause) for a specified time, and if an exception occurs, the thread is awakened. The isAlive() method indicates whether the thread is activated, returns true if it is activated, or false if it is not.
(2)getUp() method obtains the current thread through current Thread () method, interrupt() method wakes up the thread, isInterrupted judges whether the thread is awakened. When a thread is awakened, a wake-up exception is thrown if the dormant sleep() method is called.
(3) The join() method of threads in the main() main method is to wait for one or more threads to finish running before running the getUp() method.