File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Thread question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Thread question" Watch "Thread question" New topic

Thread question

Valentin Ivanov
Ranch Hand

Joined: Nov 20, 2008
Posts: 38

Nikojava's Question 66

Why the main thread behave like notifyAll() has called and prints the number's value? I thought the main thread should wait until either notify() or notifyAll() is called.
Siva Masilamani
Ranch Hand

Joined: Sep 19, 2008
Posts: 385
I came across one sucn situation myself and here is the response for my doubt.



Failure is not an option.
Valentin Ivanov
Ranch Hand

Joined: Nov 20, 2008
Posts: 38

Thank you Siva,
When a Thread dies, it calls notifyAll()

I was thinking for this but I was not sure
Henry Wong

Joined: Sep 28, 2004
Posts: 20532

Yes, with the current implementation of threads, the cleanup code does indeed call the notifyAll() method on the Thread class. The reason that this is done is because the threads who are calling the join() method for this exiting thread, is doing so by calling the wait() method.

As mentioned, this is an implementation detail, and hence, may be changed in the future.


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
I agree. Here's the link:
subject: Thread question
It's not a secret anymore!