• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Threads

 
Chandana Garlapati
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This question is from whizlabs


output: Trying to notify

My question is why only Tring to notify is printed? why notified is in waiting state???
can anyone please explain this program
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
notifyAll must be called on the corresponding instance, not on the class itself. Hence the Thread waits forever.
 
Ken Truitt
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The wait/notification scheme fails because the code that is supposed to notify is synchronized
on the class object, while the code that is waiting is synchronized on an instance of that
class. Different locks, they don't communicate. That is, 'this' refers to an instance, and the
[classname].class formulation refers to the class object.
 
Chandana Garlapati
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a Lot! for both
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic