I planProgramChanged to multi-thread. Several items are found in the test to reflect the changes. first look at them.CodeRight:
Class testmain extends thread {</P> <p> Public testmain () {<br/> super ("current thread 1 "); <br/>}< br/> Public void run () {</P> <p> for (INT I = 0; I <10; I ++) {<br/> system. out. println (thread. currentthread (). getname () + ":" + I); <br/> try {<br/> thread. sleep (100); <br/>} catch (interruptedexception e) {<br/> E. printstacktrace (); <br/>}</P> <p> class testmain1 extends thread {</ p> <p> Public testmain1 () {<br/> super ("current thread 2"); <br/>}< br/> Public void run () {</P> <p> for (INT I = 0; I <10; I ++) {<br/> system. out. println (thread. currentthread (). getname () + ":" + I); <br/> try {<br/> thread. sleep (8000); <br/>} catch (interruptedexception e) {<br/> E. printstacktrace (); <br/>}</P> <p> public class threadtest {</P> <p> Public static void main (string [] ARGs) throws exception {<br/> testmain T = new testmain (); <br/> testmain1 T1 = new testmain1 (); <br/> T. start (); <br/> t1.start (); <br/> T. join (); <br/> t1.join (); <br/> system. out. println (111); <br/>}</P> <p>}
In the previous code, if there is no join, the main thread continues to execute after two sub-threads are scheduled. If there is a join, then, we will wait until the sub-thread completes execution and then execute the print "111" of the main thread ". No matter whether there is a join, the program will wait until the sub-thread ends, instead of the end of the main thread after the end of the non-pipe thread.