Study Join
/** * existing T1, T2, T3 three threads, how do you guarantee T2 execution after T1 execution, T3 execute after T2 execution? * @author user * */public class test3 {public static void main (String[] args) throws interruptedexception {thread t1 = new thread (New t1 ()); Thread t2 = new thread (New t2 ()); Thread t3 = new thread (New t3 ()); T1.start (); T1.join (); T2.start (); T2.join (); T3.start (); T3.join ();}} class t1 implements runnable{@Overridepublic void run () {system.out.println ( Thread.CurrentThread () + "T1"); Try {thread.sleep (3000);} catch (interruptedexception e) {e.printstacktrace ();}} class t2 implements runnable{@Overridepublic void run () {system.out.println ( Thread.CurrentThread () + "T2"); Try {thread.sleep (3000);} catch (interruptedexception e) {e.printstacktrace ();}} class t3 implements runnable{@Overridepublic void run () {system.out.println (Thread.CurrentThread () + "T3"); try { Thread.Sleep (3000);} catch (interruptedexception e) {e.printstacktrace ();}}
This article is from the "12212886" blog, please be sure to keep this source http://12222886.blog.51cto.com/12212886/1964196
Existing T1, T2, T3 three threads, how do you ensure that T2 execution after T1 execution, T3 execution after T2 execution?