Share Series --Thread # join () in Java source code and did not notify, how is blocked threads are awakened? The answer in the JVM

A few days ago I saw a face questions, how to control thread execution order. The answer is Thread # join ().

 

Read join () source code, a bit puzzled, no arguments join () calls Thread # wait (0); this is a way of unlimited obstruction. And wait (0) or in the while loop to prevent false wake. Then the guarantee has been sleeping.

 

Who calls the notify () / notifyAll () ??? reverse thrust results from the implementation of the code, we know for sure is performed wake up somewhere.

 

So today it would like search, the Internet was really analyzed the join () source code, and found a way to wake up in the underlying JVM. The timing is before they are invoked join the thread death, calling itself notifyAll () wakes up all the other threads in the thread is waiting.

Article link: https://blog.csdn.net/u010983881/article/details/80257703

Guess you like

Origin www.cnblogs.com/christmad/p/11595462.html