Meaningless Drivel is fun!*
The moose likes Threads and Synchronization and the fly likes IllegalStateMonitorException when using ReentrantReadWriteLock Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "IllegalStateMonitorException when using ReentrantReadWriteLock" Watch "IllegalStateMonitorException when using ReentrantReadWriteLock" New topic
Author

IllegalStateMonitorException when using ReentrantReadWriteLock

Saha Kumar
Ranch Hand

Joined: Feb 23, 2006
Posts: 218
Hello all,

I am getting a java.lang.IllegalStateMonitorException when trying to unlock a read lock as follows: ReentrantReadWriteLock.Readlock.unlock(). I have several threads which are locking and unlocking the readlock of a given object.

The java 5 api docs state the following:


A reentrant write lock intrinsically defines an owner and can only be released by the thread that acquired it. In contrast, in this implementation, the read lock has no concept of ownership, and there is no requirement that the thread releasing a read lock is the same as the one that acquired it. However, this property is not guaranteed to hold in future implementations of this class.


My question is why am I getting the exception on a Readlock?

Thanks in advance.

-Saha
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
This may be a silly question, but are you certain that you successfully called lock() before calling unlock()? Or more precisely, are you sure you called lock() at least as many times as you called unlock()? Perhaps you could show the code that performs the lock() and unlock().


"I'm not back." - Bill Harding, Twister
Saha Kumar
Ranch Hand

Joined: Feb 23, 2006
Posts: 218
Hi Jim,

Thank you. I just found that there were more locks than unlocks (2 more locks). That was it. It took awhile to find.

Again thanks for your wisdom!

-Saha
Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

I just found that there were more locks than unlocks (2 more locks).

I think you mean that you unlocked more number of times than you locked. Isnt?


apigee, a better way to API!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: IllegalStateMonitorException when using ReentrantReadWriteLock