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

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

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

ReentrantLock.hasWaiters介绍

[英]Queries whether any threads are waiting on the given condition associated with this lock. Note that because timeouts and interrupts may occur at any time, a true return does not guarantee that a future signal will awaken any threads. This method is designed primarily for use in monitoring of the system state.
[中]查询是否有线程正在等待与此锁关联的给定条件。请注意,由于超时和中断可能随时发生,因此真正的返回并不保证将来的信号会唤醒任何线程。该方法主要用于监控系统状态。

代码示例

代码示例来源:origin: hierynomus/sshj

/** @return whether this promise has threads waiting on it. */
public boolean hasWaiters() {
  lock.lock();
  try {
    return lock.hasWaiters(cond);
  } finally {
    lock.unlock();
  }
}

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

/**
 * Atomically removes all of the elements from this queue.
 * The queue will be empty after this call returns.
 */
public void clear() {
  final Object[] items = this.items;
  final ReentrantLock lock = this.lock;
  lock.lock();
  try {
    int k = count;
    if (k > 0) {
      final int putIndex = this.putIndex;
      int i = takeIndex;
      do {
        items[i] = null;
      } while ((i = inc(i)) != putIndex);
      takeIndex = putIndex;
      count = 0;
      if (itrs != null)
        itrs.queueIsEmpty();
      for (; k > 0 && lock.hasWaiters(notFull); k--)
        notFull.signal();
    }
  } finally {
    lock.unlock();
  }
}

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

itrs.takeIndexWrapped();
for (; i > 0 && lock.hasWaiters(notFull); i--)
  notFull.signal();

代码示例来源:origin: hierynomus/smbj

/**
 * @return whether this promise has threads waiting on it.
 */
public boolean hasWaiters() {
  lock.lock();
  try {
    return lock.hasWaiters(cond);
  } finally {
    lock.unlock();
  }
}

代码示例来源:origin: net.schmizz/sshj

/** @return whether this promise has threads waiting on it. */
public boolean hasWaiters() {
  lock.lock();
  try {
    return lock.hasWaiters(cond);
  } finally {
    lock.unlock();
  }
}

代码示例来源:origin: com.hierynomus/sshj

/** @return whether this promise has threads waiting on it. */
public boolean hasWaiters() {
  lock.lock();
  try {
    return lock.hasWaiters(cond);
  } finally {
    lock.unlock();
  }
}

代码示例来源:origin: com.hierynomus/smbj

/**
 * @return whether this promise has threads waiting on it.
 */
public boolean hasWaiters() {
  lock.lock();
  try {
    return lock.hasWaiters(cond);
  } finally {
    lock.unlock();
  }
}

代码示例来源:origin: loveincode/Java-Multi-thread-Programming

public void notityMethod() {
  try {
    lock.lock();
    System.out.println("有没有线程正在等待newCondition?"
        + lock.hasWaiters(newCondition) + " 线程数是多少?"
        + lock.getWaitQueueLength(newCondition));
    newCondition.signal();
  } finally {
    lock.unlock();
  }
}

代码示例来源:origin: kabutz/javaspecialists

public boolean hasWaiters(Condition c) {
  return super.hasWaiters(getRealCondition(c));
}

代码示例来源:origin: NationalSecurityAgency/datawave

@Override
  public int drainTo(Collection<? super E> c, int maxElements) {
    if (c == this)
      throw new IllegalArgumentException();
    if (maxElements <= 0)
      return 0;
    final ReentrantLock lock = this.lock;
    lock.lock();
    try {
      int n = Math.min(maxElements, queue.size());
      int i = 0;
      try {
        while (i < n) {
          E x = queue.poll();
          c.add(x);
          i++;
        }
        return n;
      } finally {
        for (; i > 0 && lock.hasWaiters(notFull); i--)
          notFull.signal();
      }
    } finally {
      lock.unlock();
    }
  }
}

代码示例来源:origin: MobiVM/robovm

/**
 * Atomically removes all of the elements from this queue.
 * The queue will be empty after this call returns.
 */
public void clear() {
  final Object[] items = this.items;
  final ReentrantLock lock = this.lock;
  lock.lock();
  try {
    int k = count;
    if (k > 0) {
      final int putIndex = this.putIndex;
      int i = takeIndex;
      do {
        items[i] = null;
      } while ((i = inc(i)) != putIndex);
      takeIndex = putIndex;
      count = 0;
      if (itrs != null)
        itrs.queueIsEmpty();
      for (; k > 0 && lock.hasWaiters(notFull); k--)
        notFull.signal();
    }
  } finally {
    lock.unlock();
  }
}

代码示例来源:origin: ibinti/bugvm

/**
 * Atomically removes all of the elements from this queue.
 * The queue will be empty after this call returns.
 */
public void clear() {
  final Object[] items = this.items;
  final ReentrantLock lock = this.lock;
  lock.lock();
  try {
    int k = count;
    if (k > 0) {
      final int putIndex = this.putIndex;
      int i = takeIndex;
      do {
        items[i] = null;
      } while ((i = inc(i)) != putIndex);
      takeIndex = putIndex;
      count = 0;
      if (itrs != null)
        itrs.queueIsEmpty();
      for (; k > 0 && lock.hasWaiters(notFull); k--)
        notFull.signal();
    }
  } finally {
    lock.unlock();
  }
}

代码示例来源:origin: com.bugvm/bugvm-rt

/**
 * Atomically removes all of the elements from this queue.
 * The queue will be empty after this call returns.
 */
public void clear() {
  final Object[] items = this.items;
  final ReentrantLock lock = this.lock;
  lock.lock();
  try {
    int k = count;
    if (k > 0) {
      final int putIndex = this.putIndex;
      int i = takeIndex;
      do {
        items[i] = null;
      } while ((i = inc(i)) != putIndex);
      takeIndex = putIndex;
      count = 0;
      if (itrs != null)
        itrs.queueIsEmpty();
      for (; k > 0 && lock.hasWaiters(notFull); k--)
        notFull.signal();
    }
  } finally {
    lock.unlock();
  }
}

代码示例来源:origin: com.mobidevelop.robovm/robovm-rt

/**
 * Atomically removes all of the elements from this queue.
 * The queue will be empty after this call returns.
 */
public void clear() {
  final Object[] items = this.items;
  final ReentrantLock lock = this.lock;
  lock.lock();
  try {
    int k = count;
    if (k > 0) {
      final int putIndex = this.putIndex;
      int i = takeIndex;
      do {
        items[i] = null;
      } while ((i = inc(i)) != putIndex);
      takeIndex = putIndex;
      count = 0;
      if (itrs != null)
        itrs.queueIsEmpty();
      for (; k > 0 && lock.hasWaiters(notFull); k--)
        notFull.signal();
    }
  } finally {
    lock.unlock();
  }
}

代码示例来源:origin: com.gluonhq/robovm-rt

/**
 * Atomically removes all of the elements from this queue.
 * The queue will be empty after this call returns.
 */
public void clear() {
  final Object[] items = this.items;
  final ReentrantLock lock = this.lock;
  lock.lock();
  try {
    int k = count;
    if (k > 0) {
      final int putIndex = this.putIndex;
      int i = takeIndex;
      do {
        items[i] = null;
      } while ((i = inc(i)) != putIndex);
      takeIndex = putIndex;
      count = 0;
      if (itrs != null)
        itrs.queueIsEmpty();
      for (; k > 0 && lock.hasWaiters(notFull); k--)
        notFull.signal();
    }
  } finally {
    lock.unlock();
  }
}

代码示例来源:origin: FlexoVM/flexovm

/**
 * Atomically removes all of the elements from this queue.
 * The queue will be empty after this call returns.
 */
public void clear() {
  final Object[] items = this.items;
  final ReentrantLock lock = this.lock;
  lock.lock();
  try {
    int k = count;
    if (k > 0) {
      final int putIndex = this.putIndex;
      int i = takeIndex;
      do {
        items[i] = null;
      } while ((i = inc(i)) != putIndex);
      takeIndex = putIndex;
      count = 0;
      if (itrs != null)
        itrs.queueIsEmpty();
      for (; k > 0 && lock.hasWaiters(notFull); k--)
        notFull.signal();
    }
  } finally {
    lock.unlock();
  }
}

代码示例来源:origin: ibinti/bugvm

itrs.takeIndexWrapped();
for (; i > 0 && lock.hasWaiters(notFull); i--)
  notFull.signal();

代码示例来源:origin: FlexoVM/flexovm

itrs.takeIndexWrapped();
for (; i > 0 && lock.hasWaiters(notFull); i--)
  notFull.signal();

代码示例来源:origin: Johnnei/JavaTorrent

@Test
public void testAwaitTaskInterrupt() throws Exception {
  IOManager cut = new IOManager();
  ReentrantLock cutLock = Whitebox.getInternalState(cut, "lock");
  Condition cutCondition = Whitebox.getInternalState(cut, "newTaskEvent");
  Thread thread = new Thread(cut);
  thread.start();
  await().atMost(1, TimeUnit.SECONDS).until(() -> {
    cutLock.lock();
    try {
      cutLock.hasWaiters(cutCondition);
    } finally {
      cutLock.unlock();
    }
  });
  thread.interrupt();
  await("Worker to stop on interrupt.").until(() -> !thread.isAlive());
}

代码示例来源:origin: Johnnei/JavaTorrent

@Test
public void testAwaitTask() throws Exception {
  /*
   * There's nothing in the manager so this call must return without invoking anything so can't cause exceptions.
   */
  IOManager cut = new IOManager();
  IDiskJob diskJobMock = mock(IDiskJob.class);
  diskJobMock.process();
  ReentrantLock cutLock = Whitebox.getInternalState(cut, "lock");
  Condition cutCondition = Whitebox.getInternalState(cut, "newTaskEvent");
  Thread thread = new Thread(cut);
  thread.start();
  await().atMost(1, TimeUnit.SECONDS).until(() -> {
    cutLock.lock();
    try {
      cutLock.hasWaiters(cutCondition);
    } finally {
      cutLock.unlock();
    }
  });
  cut.addTask(diskJobMock);
  thread.join(5000);
}

相关文章