Maxim Kirilov
Maxim Kirilov

Reputation: 2739

My thread acquires the read lock but when trying to release it IllegalMonitorStateException is thrown

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?

Upvotes: 5

Views: 2087

Answers (0)

Related Questions