Java Multithreading 8 (join)

Source: Internet
Author: User

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)

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.