A detailed description of the Join method in Java multi-threading

Source: Internet
Author: User

The join () method is used to let the current thread of execution wait for the join thread to finish. The principle of implementation is to constantly check whether the join thread is alive, and let the current thread wait forever if the join thread survives.

Join () method partial implementation Details

while (IsAlive ())

{

Wait (0)

}

where wait (0) means to wait forever.

After the join thread aborts, the thread's This.notifyall () method is called, and the call to Notifyall () is called in the JVM that is not visible in the JDK, and you can see the JVM source code

Sample program:

Public CALSS threadtest{

public static void Main (string[] args) throws Exception

{

Thread parser1 = new Thread (new Runnable () {

public void Run () {}

});

Thread parser2 = new Thread (new Runnable () {

public void Run () {}

});

Parser1.start ();

Parser2.start ();

Parser1.join ();

Parser2.join ();

System.out.println ("All parser finish");

}

}

A detailed description of the Join method in Java multi-threading

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.