Example usage for java.util.concurrent.locks ReentrantReadWriteLock getQueueLength

List of usage examples for java.util.concurrent.locks ReentrantReadWriteLock getQueueLength

Introduction

In this page you can find the example usage for java.util.concurrent.locks ReentrantReadWriteLock getQueueLength.

Prototype

public final int getQueueLength() 

Source Link

Document

Returns an estimate of the number of threads waiting to acquire either the read or write lock.

Usage

From source file:org.bremersee.objectlock.ObjectReadWriteLockImpl.java

@Override
public void unlockReading(Object obj) {

    if (obj == null) {
        return;/*w w  w .java2  s  .com*/
    }
    synchronized (locks) {
        ReentrantReadWriteLock l = locks.get(obj);
        if (l != null) {
            l.readLock().unlock();
            if (l.getQueueLength() == 0) {
                l = locks.remove(obj);
                returnLock(l);
            }
        }
    }
}

From source file:org.bremersee.objectlock.ObjectReadWriteLockImpl.java

@Override
public void unlockWriting(Object obj) {

    if (obj == null) {
        return;/*from   w  ww  .  ja v a  2 s . c o  m*/
    }
    synchronized (locks) {
        ReentrantReadWriteLock l = locks.get(obj);
        if (l != null) {
            l.writeLock().unlock();
            if (l.getQueueLength() == 0) {
                l = locks.remove(obj);
                returnLock(l);
            }
        }
    }
}