This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes IllegalMonitorStateException doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "IllegalMonitorStateException doubt" Watch "IllegalMonitorStateException doubt" New topic
Author

IllegalMonitorStateException doubt

Deepak Borania
Ranch Hand

Joined: Jul 28, 2009
Posts: 45
GIven the following code :


Can someone please tell me why does the above code result in IllegalMonitorStateException at runtime?

And please explain a little about synchronized code blocks. I just can't seem to get hang of them.

Thanks
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19723
    
  20

You synchronize on whatever.class, then try to get the lock on "this". You can only call wait, notify and notifyAll on objects you synchronize on.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: IllegalMonitorStateException doubt