5

my application is deployed on Weblogic 10.3.5 with java 6 update 30. I encountered with the following error while executed this code lines:

    lock.readLock().lock();
    try {
        holder = cache.get(configName);
        // If it exists in the cache, return it
        if (holder != null)
            return holder;
    } finally {
        lock.readLock().unlock();
    }

while lock is initialized during class loading:

private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();

cache is:

private Map<String, ConfigurationHolder> cache = new HashMap<String,ConfigurationHolder>();

Suddenly IllegalMonitorStateException were thrown:

Caused by: java.lang.IllegalMonitorStateException
    at java.util.concurrent.locks.ReentrantReadWriteLock$Sync.tryReleaseShared(ReentrantReadWriteLock.java:363)
    at java.util.concurrent.locks.AbstractQueuedSynchronizer.releaseShared(AbstractQueuedSynchronizer.java:1317)
    at java.util.concurrent.locks.ReentrantReadWriteLock$ReadLock.unlock(ReentrantReadWriteLock.java:745) 

I read here similar description to this scenario.

Anyone have any idea why this is happen?

Maxim Kirilov
  • 2,639
  • 24
  • 49
  • 3
    is it possible that one of those calls inside the try block is incorrectly releasing the lock? – jtahlborn Aug 23 '12 at 14:02
  • It could be a bug in the JVM, can you try a more recent update of Java? – Peter Lawrey Aug 23 '12 at 14:02
  • no, because cache object is a Map. – Maxim Kirilov Aug 24 '12 at 16:43
  • 1
    Is it possible that another thread has released the lock, too? Your snippet does not show what other code might access lock. If I'm right, an IllegalMonitorStateException is only thrown when releasing a lock that you don't own, or is no longer there. – Tom Aug 25 '12 at 21:34

0 Answers0