Join (): Join. If a thread executes a join statement, then a new thread is added and the language IJ is executed.
The thread of the sentence must give in to the newly added line enters upgradeable to complete the task before it can continue execution.
ImportJava.util.Scanner;Import StaticSun.misc.Version.print; Public classEX10 { Public Static voidMain (string[] args) {Mom m=NewMom (); M.run ();//don't you need to run it? Why are they two ?//M.start (); }}classMomextendsthread{@Override Public voidrun () {System.out.println ("The mother washes the vegetables"); System.out.println ("Mom's cutting the vegetables."); System.out.println ("Mom was ready to stir-fry, but found no soy sauce."); //mom called son soy sauce .Son s =NewSon (); S.start (); Try{s.join (); } Catch(interruptedexception e) {e.printstacktrace (); } System.out.println ("Mom, keep cooking."); System.out.println ("Dinner is haha haha haha!!!!! "); System.out.println (); }}classSonextendsthread{@Override Public voidrun () {System.out.println ("The son went downstairs."); System.out.println ("Hit the soy sauce."); System.out.println ("The son gave the soy sauce to his mother."); }}
0
Java Multithreading 8 (join)