Java Code Examples for java.util.concurrent.locks.ReentrantReadWriteLock#getReadLockCount()

The following examples show how to use java.util.concurrent.locks.ReentrantReadWriteLock#getReadLockCount() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CmdDisplayLockStatus.java    From linstor-server with GNU General Public License v3.0 6 votes vote down vote up
private void reportRwLock(PrintStream output, String label, ReadWriteLock readWriteLock)
{
    ReentrantReadWriteLock reentrantReadWriteLock = (ReentrantReadWriteLock) readWriteLock;

    boolean writeLocked = reentrantReadWriteLock.isWriteLocked();
    boolean fair = reentrantReadWriteLock.isFair();
    boolean queued = reentrantReadWriteLock.hasQueuedThreads();
    int readerCount = reentrantReadWriteLock.getReadLockCount();

    output.printf(
        RWLOCK_FORMAT,
        label,
        writeLocked ? "Y" : "N",
        fair ? "Y" : "N",
        queued ? "Y" : "N",
        readerCount
    );
}
 
Example 2
Source File: ReentrantReadWriteLockGroup.java    From data-prep with Apache License 2.0 3 votes vote down vote up
/**
 * Returns <tt>true</tt> if the specified lock is held by a thread or is asked (some threads are blocking and
 * waiting to acquire the lock) and <tt>otherwise</tt>.
 * 
 * @param lock the specified lock
 * @return <tt>true</tt> if the specified lock is held by a thread or is asked (some threads are blocking and
 * waiting to acquire the lock) and <tt>otherwise</tt>.
 */
private boolean lockHeldOrAsked(ReentrantReadWriteLock lock) {
    if (lock.hasQueuedThreads() || lock.getReadLockCount() > 0 || lock.isWriteLocked()) {
        return true;
    }
    return false;
}