aspose file tools*
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
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: 19722
    
  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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: IllegalMonitorStateException doubt