Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thread question

 
Valentin Ivanov
Ranch Hand
Posts: 38
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 385
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I came across one sucn situation myself and here is the response for my doubt.

here
 
Valentin Ivanov
Ranch Hand
Posts: 38
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Siva,
When a Thread dies, it calls notifyAll()

I was thinking for this but I was not sure
 
Henry Wong
author
Marshal
Pie
Posts: 20997
76
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic