Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

IllegalMonitorStateException  RSS feed

 
Paul Michael
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i created these classes and got that exception. i tried using the synchronized(this) statement instead and it worked... it's a bit confusing because letters and numbers are two diff objects and i'm wondering why my first aproach didn't work... hewp!
 
Marcela Blei
Ranch Hand
Posts: 477
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you look at the API doc. at the Object.notify method for example, you can find the following:
A thread becomes the owner of the object's monitor in one of three ways:
-By executing a synchronized instance method of that object.
-By executing the body of a synchronized statement that synchronizes on the object.
-For objects of type Class, by executing a synchronized static method of that class.
So, what does this mean: That you have to own the thread´┐Żs monitor for using notify, for example. Read the API doc carefully for a deep detail of the following methods from Object: notify, wait, notifyAll.
 
Paul Michael
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i see!!! i should have specifically used the letters.notify()/letters.notifyAll() and numbers.notify()/numbers.notifyAll() instead!
thanks a lot Marcela Blei!!!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!