wood burning stoves*
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Thread question" Watch "Thread question" New topic
Author

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.

here


SCJP 6,SCWCD 5,SCBCD 5

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
author
Sheriff

Joined: Sep 28, 2004
Posts: 18500
    
  40

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.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
Consider Paul's rocket mass heater.
 
subject: Thread question
 
Similar Threads
another question from nikos
join method
Thread-doubt on wait
a Thread Question from Nikos Blog
Problem in Threading - 2