wood burning stoves 2.0
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Threads 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 "Threads" Watch "Threads" New topic


Chandana Garlapati
Ranch Hand

Joined: Jul 06, 2009
Posts: 97
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

Joined: Feb 23, 2009
Posts: 1183
notifyAll must be called on the corresponding instance, not on the class itself. Hence the Thread waits forever.

JDBCSupport - An easy to use, light-weight JDBC framework -
Ken Truitt
Ranch Hand

Joined: Aug 23, 2007
Posts: 124

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.

SCJP 88% | SCWCD 84%
Chandana Garlapati
Ranch Hand

Joined: Jul 06, 2009
Posts: 97
Thanks a Lot! for both
I agree. Here's the link: http://aspose.com/file-tools
subject: Threads
It's not a secret anymore!