当前位置: 首页>>代码示例>>Java>>正文


Java AtomicBoolean.wait方法代码示例

本文整理汇总了Java中java.util.concurrent.atomic.AtomicBoolean.wait方法的典型用法代码示例。如果您正苦于以下问题:Java AtomicBoolean.wait方法的具体用法?Java AtomicBoolean.wait怎么用?Java AtomicBoolean.wait使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.concurrent.atomic.AtomicBoolean的用法示例。


在下文中一共展示了AtomicBoolean.wait方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: waitIfPaused

import java.util.concurrent.atomic.AtomicBoolean; //导入方法依赖的package包/类
/** @return true - if task should be interrupted; false - otherwise */
private boolean waitIfPaused() {
	AtomicBoolean pause = engine.getPause();
	synchronized (pause) {
		if (pause.get()) {
			log(LOG_WAITING_FOR_RESUME);
			try {
				pause.wait();
			} catch (InterruptedException e) {
				L.e(LOG_TASK_INTERRUPTED, memoryCacheKey);
				return true;
			}
			log(LOG_RESUME_AFTER_PAUSE);
		}
	}
	return checkTaskIsNotActual();
}
 
开发者ID:benniaobuguai,项目名称:android-project-gallery,代码行数:18,代码来源:LoadAndDisplayImageTask.java

示例2: waitForConditionEx

import java.util.concurrent.atomic.AtomicBoolean; //导入方法依赖的package包/类
public static boolean waitForConditionEx(final AtomicBoolean condition, long timeout)
throws InterruptedException
  {
      synchronized (condition) {
          long startTime = System.currentTimeMillis();
          while (!condition.get()) {
              condition.wait(timeout);
              if (System.currentTimeMillis() - startTime >= timeout ) {
                  break;
              }
          }
      }
      return condition.get();
  }
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:15,代码来源:Util.java

示例3: waitFocused

import java.util.concurrent.atomic.AtomicBoolean; //导入方法依赖的package包/类
static void waitFocused(Window w, AtomicBoolean b) {
    try {
        synchronized(b) {
            if (w.isFocusOwner()) {
                return;
            }
            b.wait(3000);
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    if (!w.isFocusOwner()) {
        throw new RuntimeException("Can't make " + w + " focus owner");
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:16,代码来源:TestAlwaysOnTopBeforeShow.java

示例4: updateMeta

import java.util.concurrent.atomic.AtomicBoolean; //导入方法依赖的package包/类
/**
 * Update ZK or META.  This can take a while if for example the
 * hbase:meta is not available -- if server hosting hbase:meta crashed and we are
 * waiting on it to come back -- so run in a thread and keep updating znode
 * state meantime so master doesn't timeout our region-in-transition.
 * Caller must cleanup region if this fails.
 */
boolean updateMeta(final HRegion r, long masterSystemTime) {
  if (this.server.isStopped() || this.rsServices.isStopping()) {
    return false;
  }
  // Object we do wait/notify on.  Make it boolean.  If set, we're done.
  // Else, wait.
  final AtomicBoolean signaller = new AtomicBoolean(false);
  PostOpenDeployTasksThread t = new PostOpenDeployTasksThread(r,
    this.server, this.rsServices, signaller, masterSystemTime);
  t.start();
  // Post open deploy task:
  //   meta => update meta location in ZK
  //   other region => update meta
  // It could fail if ZK/meta is not available and
  // the update runs out of retries.
  long now = System.currentTimeMillis();
  long lastUpdate = now;
  boolean tickleOpening = true;
  while (!signaller.get() && t.isAlive() && !this.server.isStopped() &&
      !this.rsServices.isStopping() && isRegionStillOpening()) {
    long elapsed = now - lastUpdate;
    if (elapsed > 120000) { // 2 minutes, no need to tickleOpening too often
      // Only tickle OPENING if postOpenDeployTasks is taking some time.
      lastUpdate = now;
      if (useZKForAssignment) {
        tickleOpening = coordination.tickleOpening(
          ord, regionInfo, rsServices, "post_open_deploy");
      }
    }
    synchronized (signaller) {
      try {
        // Wait for 10 seconds, so that server shutdown
        // won't take too long if this thread happens to run.
        if (!signaller.get()) signaller.wait(10000);
      } catch (InterruptedException e) {
        // Go to the loop check.
      }
    }
    now = System.currentTimeMillis();
  }
  // Is thread still alive?  We may have left above loop because server is
  // stopping or we timed out the edit.  Is so, interrupt it.
  if (t.isAlive()) {
    if (!signaller.get()) {
      // Thread still running; interrupt
      LOG.debug("Interrupting thread " + t);
      t.interrupt();
    }
    try {
      t.join();
    } catch (InterruptedException ie) {
      LOG.warn("Interrupted joining " +
        r.getRegionInfo().getRegionNameAsString(), ie);
      Thread.currentThread().interrupt();
    }
  }

  // Was there an exception opening the region?  This should trigger on
  // InterruptedException too.  If so, we failed.  Even if tickle opening fails
  // then it is a failure.
  return ((!Thread.interrupted() && t.getException() == null) && tickleOpening);
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:70,代码来源:OpenRegionHandler.java


注:本文中的java.util.concurrent.atomic.AtomicBoolean.wait方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。