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

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

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

ReentrantLock.hasQueuedThreads介绍

[英]Queries whether any threads are waiting to acquire this lock. Note that because cancellations may occur at any time, a truereturn does not guarantee that any other thread will ever acquire this lock. This method is designed primarily for use in monitoring of the system state.
[中]查询是否有线程正在等待获取此锁。请注意,由于取消操作可能随时发生,truereturn并不保证任何其他线程都会获得该锁。该方法主要用于监控系统状态。

代码示例

代码示例来源:origin: google/guava

/**
 * Returns whether any threads are waiting to enter this monitor. Note that because cancellations
 * may occur at any time, a {@code true} return does not guarantee that any other thread will ever
 * enter this monitor. This method is designed primarily for use in monitoring of the system
 * state.
 */
public boolean hasQueuedThreads() {
 return lock.hasQueuedThreads();
}

代码示例来源:origin: prestodb/presto

/**
 * Returns whether any threads are waiting to enter this monitor. Note that because cancellations
 * may occur at any time, a {@code true} return does not guarantee that any other thread will ever
 * enter this monitor. This method is designed primarily for use in monitoring of the system
 * state.
 */
public boolean hasQueuedThreads() {
 return lock.hasQueuedThreads();
}

代码示例来源:origin: google/j2objc

/**
 * Returns whether any threads are waiting to enter this monitor. Note that because cancellations
 * may occur at any time, a {@code true} return does not guarantee that any other thread will ever
 * enter this monitor. This method is designed primarily for use in monitoring of the system
 * state.
 */
public boolean hasQueuedThreads() {
 return lock.hasQueuedThreads();
}

代码示例来源:origin: wildfly/wildfly

/**
 * Returns whether any threads are waiting to enter this monitor. Note that because cancellations
 * may occur at any time, a {@code true} return does not guarantee that any other thread will ever
 * enter this monitor. This method is designed primarily for use in monitoring of the system
 * state.
 */
public boolean hasQueuedThreads() {
 return lock.hasQueuedThreads();
}

代码示例来源:origin: glyptodon/guacamole-client

/**
 * Returns whether there are threads waiting for read access to the
 * Guacamole instruction stream.
 *
 * @return true if threads are waiting for read access the Guacamole
 *         instruction stream, false otherwise.
 */
@Override
public boolean hasQueuedReaderThreads() {
  return readerLock.hasQueuedThreads();
}

代码示例来源:origin: thinkaurelius/titan

@Override
public boolean inUse() {
  return super.isLocked() || super.hasQueuedThreads();
}

代码示例来源:origin: glyptodon/guacamole-client

@Override
public boolean hasQueuedWriterThreads() {
  return writerLock.hasQueuedThreads();
}

代码示例来源:origin: JanusGraph/janusgraph

@Override
public boolean inUse() {
  return super.isLocked() || super.hasQueuedThreads();
}

代码示例来源:origin: kiegroup/jbpm

protected void releaseAndCleanLock(Long id, RuntimeEngine runtime) {
  if (id != null) {
    ReentrantLock lock = engineLocks.get(id);
    if (lock != null) {
      if (!lock.hasQueuedThreads()) {
        logger.debug("Removing lock {} from list as non is waiting for it by {}", lock, runtime);
        engineLocks.remove(id);
      }
      if (lock.isHeldByCurrentThread()) {
        lock.unlock();
        logger.debug("{} unlocked by {}", lock, runtime);
      }
    }
  }
  
}

代码示例来源:origin: kiegroup/jbpm

protected void createLockOnGetEngine(Long id, RuntimeEngine runtime) {
  if (!isUseLocking()) {
    logger.debug("Locking on runtime manager disabled");
    return;
  }
  
  if (id != null) {
    ReentrantLock newLock = new ReentrantLock();
    ReentrantLock lock = engineLocks.putIfAbsent(id, newLock);
    if (lock == null) {
      lock = newLock;
      logger.debug("New lock created as it did not exist before");
    } else {
      logger.debug("Lock exists with {} waiting threads", lock.getQueueLength());
    }
    logger.debug("Trying to get a lock {} for {} by {}", lock, id, runtime);
    lock.lock();
    logger.debug("Lock {} taken for {} by {} for waiting threads by {}", lock, id, runtime, lock.hasQueuedThreads());
    
  }
  
}

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

@Override
 public void run() {
  try {
   tx1 = txMgr.masqueradeAs(msg);
  } catch (InterruptedException e) {
   e.printStackTrace();
   throw new RuntimeException(e);
  }
  msg.process(dm);
  TXStateProxy existingTx = masqueradeToRollback();
  latch.countDown();
  await()
    .until(() -> tx1.getLock().hasQueuedThreads());
  rollbackTransaction(existingTx);
 }
});

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

@Override
 public void run() {
  tx1 = txMgr.getHostedTXState(txid);
  assertNull(tx1);
  tx1 = txMgr.getOrSetHostedTXState(txid, msg);
  assertNotNull(tx1);
  assertTrue(txMgr.getLock(tx1, txid));
  latch.countDown();
  await()
    .until(() -> tx1.getLock().hasQueuedThreads());
  txMgr.removeHostedTXState(txid);
  tx2 = txMgr.getOrSetHostedTXState(txid, msg);
  assertNotNull(tx2);
  assertTrue(txMgr.getLock(tx2, txid));
  tx2.getLock().unlock();
  tx1.getLock().unlock();
 }
});

代码示例来源:origin: com.vaadin/vaadin-server

if (((ReentrantLock) lockInstance).hasQueuedThreads()) {

代码示例来源:origin: com.google.guava/guava-jdk5

/**
 * Returns whether any threads are waiting to enter this monitor. Note that because cancellations
 * may occur at any time, a {@code true} return does not guarantee that any other thread will ever
 * enter this monitor. This method is designed primarily for use in monitoring of the system
 * state.
 */
public boolean hasQueuedThreads() {
 return lock.hasQueuedThreads();
}

代码示例来源:origin: org.apache.ratis/ratis-proto-shaded

/**
 * Returns whether any threads are waiting to enter this monitor. Note that because cancellations
 * may occur at any time, a {@code true} return does not guarantee that any other thread will ever
 * enter this monitor. This method is designed primarily for use in monitoring of the system
 * state.
 */
public boolean hasQueuedThreads() {
 return lock.hasQueuedThreads();
}

代码示例来源:origin: io.prestosql/presto-jdbc

/**
 * Returns whether any threads are waiting to enter this monitor. Note that because cancellations
 * may occur at any time, a {@code true} return does not guarantee that any other thread will ever
 * enter this monitor. This method is designed primarily for use in monitoring of the system
 * state.
 */
public boolean hasQueuedThreads() {
 return lock.hasQueuedThreads();
}

代码示例来源:origin: org.kill-bill.billing/killbill-platform-osgi-bundles-logger

/**
 * Returns whether any threads are waiting to enter this monitor. Note that because cancellations
 * may occur at any time, a {@code true} return does not guarantee that any other thread will ever
 * enter this monitor. This method is designed primarily for use in monitoring of the system
 * state.
 */
public boolean hasQueuedThreads() {
 return lock.hasQueuedThreads();
}

代码示例来源:origin: org.testifyproject.external/external-guava

/**
 * Returns whether any threads are waiting to enter this monitor. Note that because cancellations
 * may occur at any time, a {@code true} return does not guarantee that any other thread will ever
 * enter this monitor. This method is designed primarily for use in monitoring of the system
 * state.
 */
public boolean hasQueuedThreads() {
 return lock.hasQueuedThreads();
}

代码示例来源:origin: org.apache.activemq/artemis-jms-client-all

protected void doSend(byte[] data, int offset, int length, boolean acquire_lock, boolean flush) throws Exception {
  if(out == null)
    return;
  out.writeInt(length); // write the length of the data buffer first
  out.write(data,offset,length);
  if(!flush || (acquire_lock && send_lock.hasQueuedThreads()))
    return; // don't flush as some of the waiting threads will do the flush, or flush is false
  out.flush(); // may not be very efficient (but safe)
}

代码示例来源:origin: apache/activemq-artemis

protected void doSend(byte[] data, int offset, int length, boolean acquire_lock, boolean flush) throws Exception {
  if(out == null)
    return;
  out.writeInt(length); // write the length of the data buffer first
  out.write(data,offset,length);
  if(!flush || (acquire_lock && send_lock.hasQueuedThreads()))
    return; // don't flush as some of the waiting threads will do the flush, or flush is false
  out.flush(); // may not be very efficient (but safe)
}

相关文章