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