com.google.common.util.concurrent.Monitor.waitFor()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(1.1k)|赞(0)|评价(0)|浏览(122)

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

Monitor.waitFor介绍

[英]Waits for the guard to be satisfied. Waits indefinitely, but may be interrupted. May be called only by a thread currently occupying this monitor.
[中]等待警卫满意。无限期等待,但可能会被中断。只能由当前占用此监视器的线程调用。

代码示例

代码示例来源:origin: dCache/dcache

public void awaitTermination() throws InterruptedException
{
  monitor.enter();
  try {
    monitor.waitFor(isTerminated);
  } finally {
    monitor.leave();
  }
}

代码示例来源:origin: dCache/dcache

@Override
public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException
{
  monitor.enter();
  try {
    return monitor.waitFor(isTerminated, timeout, unit);
  } finally {
    monitor.leave();
  }
}

代码示例来源:origin: apache/jackrabbit-oak

boolean waitForRead(int time, TimeUnit unit) throws InterruptedException {
  readMonitor.enter();
  try {
    return readMonitor.waitFor(new Monitor.Guard(readMonitor) {
      @Override
      public boolean isSatisfied() {
        return reading;
      }
    }, time, unit);
  } finally {
    readMonitor.leave();
  }
}

相关文章