This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan 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 Android Security Essentials Live Lessons this week in the Android 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: 19655
    
  18

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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: IllegalMonitorStateException doubt
 
Similar Threads
wait() and notifyAll()
problem with wait()- notify()
Thread -IllegalMonitorStateException and IllegalThreadStateException
wait( ) method behind the scene ...
IllegalMonitorStateException from notify()