File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Threads and Synchronization and the fly likes wait, notifyAll IllegalMonitorStateException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "wait, notifyAll IllegalMonitorStateException" Watch "wait, notifyAll IllegalMonitorStateException" New topic
Author

wait, notifyAll IllegalMonitorStateException

Maciej Kowalski
Greenhorn

Joined: Apr 22, 2013
Posts: 6
Hi everybody

I am Java newbie (and mid-RoR developer).

I have a simple program.
Ball is shared amont players. Ball should be passed to random Player.

Ok here goes the code:



But it dont works.
I get exception: IllegalMonitorStateException.

How can I fix this?
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

If you're going to call X.wait() or X.notify() or X.notifyAll(), you have to be holding X's monitor (lock). That is, you have to be in a sync block that is synced on X.


Maciej Kowalski
Greenhorn

Joined: Apr 22, 2013
Posts: 6
Jeff Verdegan wrote:If you're going to call X.wait() or X.notify() or X.notifyAll(), you have to be holding X's monitor (lock). That is, you have to be in a sync block that is synced on X.




Thanks for the quick reply.

IT WORKS!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: wait, notifyAll IllegalMonitorStateException