aspose file tools
The moose likes Threads and Synchronization and the fly likes IllegalMonitorStateException Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "IllegalMonitorStateException" Watch "IllegalMonitorStateException" New topic
Author

IllegalMonitorStateException

Paul Michael
Ranch Hand

Joined: Jul 02, 2001
Posts: 697
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!


SCJP 1.2 (89%), SCWCD 1.3 (94%), IBM 486 (90%), SCJA Beta (96%), SCEA (91% / 77%), SCEA 5 P1 (77%), SCBCD 5 (85%)
Marcela Blei
Ranch Hand

Joined: Jun 28, 2000
Posts: 477
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

Joined: Jul 02, 2001
Posts: 697
i see!!! i should have specifically used the letters.notify()/letters.notifyAll() and numbers.notify()/numbers.notifyAll() instead!
thanks a lot Marcela Blei!!!
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: IllegalMonitorStateException
 
Similar Threads
Question on thread q.2 pg 734
About the problem of producer and consumer
Buffering using Thread Synchronization
Multichat Application
Use of volatile variable with wait() and notify()