The JDK is interpreted as Waits for the thread to die. Wait for this thread to finish before the next thread can run.
Instance requirements:
Now there are T1, T2, T3 three threads, how do you ensure that T2 execution after T1 execution, T3 after the T2 execution
Implementation code:
Packagecom.st.lesson02; Public classTest01 {//1. Now there are T1, T2, T3 three threads, how do you ensure that T2 after T1 execution, T3 after the execution of T2 executed Public Static voidMain (string[] args)throwsinterruptedexception {Thread Th1=NewThread01 (); Thread Th2=NewThread02 (); Thread Th3=NewThread03 (); Th1.start (); Th1.join (); System.out.println ("Thread01 Run End ... "); Th2.start (); Th2.join (); System.out.println ("Thread02 Run End ... "); Th3.start (); Th3.join (); System.out.println ("Thread03 Run End ... "); System.out.println ("------Main function-------"); }}classThread01extendsthread{ Public voidrun () {System.out.println ("Thread01...running ..."); Try{Thread.Sleep (2000); } Catch(interruptedexception e) {e.printstacktrace (); } }}classThread02extendsthread{ Public voidrun () {System.out.println ("Thread02...running ..."); Try{Thread.Sleep (500); } Catch(interruptedexception e) {e.printstacktrace (); } }}classThread03extendsthread{ Public voidrun () {System.out.println ("Thread03...running ..."); Try{Thread.Sleep (1000); } Catch(interruptedexception e) {e.printstacktrace (); } }}
Run:
Join Usages in Java threads