thread.join() will call thread.wait(), but who and when notifies (either with thread.notify() or notifyAll()) the thread.wait()?
As we know, thread join will wait for the thread to be completed, but who calls notify on it?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Edit:
Oh, you are talking about inside of the
Threadobject itself. Inside ofjoin()we do see await(). Something like:The
notify()for this is handled by theThreadsubsystem. When therun()method finishes, thenotify()is called on theThreadobject. I’m not sure if the code that actually callsnotify()can be seen — it seems to be done in native code.No user code needs to call
notify()on thatThreadobject. The JavaThreadcode handles this internally. Once the thread finishes, thejoin()call will return.For example, the following code will execute fine and the
join()call will return fine without anywait()ornotify()calls.It is important to note that this behavior should probably not be relied upon. The
notify()call is internal to the thread system. You should usejoin()if you are waiting for a thread to finish.