當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。