• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

IllegalStateMonitorException when using ReentrantReadWriteLock

 
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 1638
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
reply
    Bookmark Topic Watch Topic
  • New Topic