Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

IllegalStateMonitorException when using ReentrantReadWriteLock

 
Saha Kumar
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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().
 
Saha Kumar
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic