java.util.concurrent.locks.ReentrantReadWriteLock.getQueueLength()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(5.3k)|赞(0)|评价(0)|浏览(115)

本文整理了Java中java.util.concurrent.locks.ReentrantReadWriteLock.getQueueLength方法的一些代码示例,展示了ReentrantReadWriteLock.getQueueLength的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ReentrantReadWriteLock.getQueueLength方法的具体详情如下:
包路径:java.util.concurrent.locks.ReentrantReadWriteLock
类名称:ReentrantReadWriteLock
方法名:getQueueLength

ReentrantReadWriteLock.getQueueLength介绍

[英]Returns an estimate of the number of threads waiting to acquire either the read or write lock. The value is only an estimate because the number of threads may change dynamically while this method traverses internal data structures. This method is designed for use in monitoring of the system state, not for synchronization control.
[中]返回等待获取读锁或写锁的线程数的估计值。该值只是一个估计值,因为当该方法遍历内部数据结构时,线程的数量可能会动态变化。该方法设计用于监控系统状态,而不是同步控制。

代码示例

代码示例来源:origin: apache/hbase

@VisibleForTesting
public void waitForWaiters(T id, int numWaiters) throws InterruptedException {
 for (ReentrantReadWriteLock readWriteLock;;) {
  readWriteLock = lockPool.get(id);
  if (readWriteLock != null) {
   synchronized (readWriteLock) {
    if (readWriteLock.getQueueLength() >= numWaiters) {
     return;
    }
   }
  }
  Thread.sleep(50);
 }
}

代码示例来源:origin: org.apache.hadoop/hadoop-hdfs

/**
 * Returns the QueueLength of waiting threads.
 *
 * A larger number indicates greater lock contention.
 *
 * @return int - Number of threads waiting on this lock
 */
public int getQueueLength() {
 return coarseLock.getQueueLength();
}

代码示例来源:origin: i2p/i2p.i2p

/**
 *  @return true if the lock was acquired
 *  @since 0.8.11 moved from DecayingHashSet
 */
protected boolean getWriteLock() {
  try {
    boolean rv = _reorganizeLock.writeLock().tryLock(5000, TimeUnit.MILLISECONDS);
    if (!rv)
      _log.error("no lock, size is: " + _reorganizeLock.getQueueLength(), new Exception("rats"));
    return rv;
  } catch (InterruptedException ie) {}
  return false;
}

代码示例来源:origin: i2p/i2p.i2p

/** @return true if the lock was acquired */
private boolean getWriteLock() {
  try {
    boolean rv = _fileLock.writeLock().tryLock(10000, TimeUnit.MILLISECONDS);
    if ((!rv) && _log.shouldLog(Log.WARN))
      _log.warn("no lock, size is: " + _fileLock.getQueueLength(), new Exception("rats"));
    return rv;
  } catch (InterruptedException ie) {}
  return false;
}

代码示例来源:origin: i2p/i2p.i2p

/** @return true if the lock was acquired */
private boolean getWriteLock() {
  try {
    boolean rv = _reorganizeLock.writeLock().tryLock(3000, TimeUnit.MILLISECONDS);
    if ((!rv) && _log.shouldLog(Log.WARN))
      _log.warn("no lock, size is: " + _reorganizeLock.getQueueLength(), new Exception("rats"));
    return rv;
  } catch (InterruptedException ie) {}
  return false;
}

代码示例来源:origin: i2p/i2p.i2p

/** @return true if the lock was acquired */
private boolean getWriteLock() {
  try {
    boolean rv = _bucketsLock.writeLock().tryLock(3000, TimeUnit.MILLISECONDS);
    if ((!rv) && _log.shouldLog(Log.WARN))
      _log.warn("no lock, size is: " + _bucketsLock.getQueueLength(), new Exception("rats"));
    return rv;
  } catch (InterruptedException ie) {}
  return false;
}

代码示例来源:origin: io.prestosql.hadoop/hadoop-apache

/**
 * Returns the QueueLength of waiting threads.
 *
 * A larger number indicates greater lock contention.
 *
 * @return int - Number of threads waiting on this lock
 */
public int getQueueLength() {
 return coarseLock.getQueueLength();
}

代码示例来源:origin: ch.cern.hadoop/hadoop-hdfs

/**
 * Returns the QueueLength of waiting threads.
 *
 * A larger number indicates greater lock contention.
 *
 * @return int - Number of threads waiting on this lock
 */
public int getQueueLength() {
 return coarseLock.getQueueLength();
}

代码示例来源:origin: org.rhq/rhq-core-plugin-container

private String getFacetLockStatus() {
  StringBuilder str = new StringBuilder("Facet lock status for [");
  str.append(getResource());
  str.append("], is-write-locked=[").append(facetAccessLock.isWriteLocked());
  str.append("], is-write-locked-by-current-thread=[").append(facetAccessLock.isWriteLockedByCurrentThread());
  str.append("], read-locks=[").append(facetAccessLock.getReadLockCount());
  str.append("], waiting-for-lock-queue-size=[").append(facetAccessLock.getQueueLength());
  str.append("]");
  return str.toString();
}

代码示例来源:origin: harbby/presto-connectors

@VisibleForTesting
 public void waitForWaiters(long id, int numWaiters) throws InterruptedException {
  for (ReentrantReadWriteLock readWriteLock;;) {
   readWriteLock = lockPool.get(id);
   if (readWriteLock != null) {
    synchronized (readWriteLock) {
     if (readWriteLock.getQueueLength() >= numWaiters) {
      return;
     }
    }
   }
   Thread.sleep(50);
  }
 }
}

代码示例来源:origin: vgrazi/java-concurrent-animated

private String status() {
 return " read locks:" + rwlock.getReadLockCount() + " writeLocks:" + rwlock.getWriteHoldCount() + " waiting:" + rwlock.getQueueLength() +"\n";
}

代码示例来源:origin: stackoverflow.com

ReentrantReadWriteLock lock = CONCURRENT_HASH_MAP.get(employee.getId());
System.out.println("lock object " + lock + "queue length "
    + lock.getQueueLength());

代码示例来源:origin: org.marketcetera/core

/**
 * Returns module info describing the current state of the module.
 *
 * @param inInitiatedFlows the set of IDs for the data flows that this
 * module has initiated
 * @param inParticipatingFlows the set of IDs for the data flows that this
 * module is participating in.
 *
 * @return the module info.
 */
final ModuleInfo getModuleInfo(DataFlowID[] inInitiatedFlows,
                DataFlowID[] inParticipatingFlows) {
  return new ModuleInfo(getURN(), getState(), inInitiatedFlows,
      inParticipatingFlows, getCreated(), getStarted(),
      getStopped(), isAutoStart(), isAutoCreated(),
      this instanceof DataReceiver, this instanceof DataEmitter,
      this instanceof DataFlowRequester, getLastStartFailure(),
      getLastStopFailure(), mLock.getReadLockCount(),
      mLock.isWriteLocked(), mLock.getQueueLength());
}

相关文章