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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: wait, notifyAll IllegalMonitorStateException
 
Similar Threads
Threads
app doesn't exit because of JOptionPane
Help with method
synchronization.. and threads !!!
Threads and instance variables