本文整理汇总了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();
}
示例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();
}
示例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");
}
}
示例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);
}