Existing T1, T2, T3 three threads, how do you ensure that T2 execution after T1 execution, T3 execution after T2 execution?

Source: Internet
Author: User

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?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.