下面列出了java.util.concurrent.locks.ReentrantReadWriteLock#getReadLockCount() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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
);
}
/**
* 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;
}