private void timedWait(final long interval, final TimeUnit timeUnit) { try { synchronized (this) { timeUnit.timedWait(this, interval); } } catch (InterruptedException handled) { // NOTE just go and send another status request to the Locator... } }
@Override public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException { long nanos = unit.toNanos(timeout); synchronized (lock) { while (true) { if (shutdown && runningTasks == 0) { return true; } else if (nanos <= 0) { return false; } else { long now = System.nanoTime(); TimeUnit.NANOSECONDS.timedWait(lock, nanos); nanos -= System.nanoTime() - now; // subtract the actual time we waited } } } }
@Override public Object get(long timeout, @Nonnull TimeUnit unit) throws InterruptedException, TimeoutException { synchronized (lock) { while (!canceled) { unit.timedWait(lock, timeout); } if (canceled) { throw new CancellationException(); } else { throw new TimeoutException(); } } } }
@Override public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException { long nanos = unit.toNanos(timeout); synchronized (lock) { while (true) { if (shutdown && runningTasks == 0) { return true; } else if (nanos <= 0) { return false; } else { long now = System.nanoTime(); TimeUnit.NANOSECONDS.timedWait(lock, nanos); nanos -= System.nanoTime() - now; // subtract the actual time we waited } } } }
@Override public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException { long nanos = unit.toNanos(timeout); synchronized (lock) { while (true) { if (shutdown && runningTasks == 0) { return true; } else if (nanos <= 0) { return false; } else { long now = System.nanoTime(); TimeUnit.NANOSECONDS.timedWait(lock, nanos); nanos -= System.nanoTime() - now; // subtract the actual time we waited } } } }
@Override public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException { long nanos = unit.toNanos(timeout); synchronized (lock) { while (true) { if (shutdown && runningTasks == 0) { return true; } else if (nanos <= 0) { return false; } else { long now = System.nanoTime(); TimeUnit.NANOSECONDS.timedWait(lock, nanos); nanos -= System.nanoTime() - now; // subtract the actual time we waited } } } }
@Override public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException { long nanos = unit.toNanos(timeout); synchronized (lock) { while (true) { if (shutdown && runningTasks == 0) { return true; } else if (nanos <= 0) { return false; } else { long now = System.nanoTime(); TimeUnit.NANOSECONDS.timedWait(lock, nanos); nanos -= System.nanoTime() - now; // subtract the actual time we waited } } } }
synchronized (this) { if (!isCompleted) { unit.timedWait(this, timeout);
@Override public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException { long nanos = unit.toNanos(timeout); synchronized (lock) { while (true) { if (shutdown && runningTasks == 0) { return true; } else if (nanos <= 0) { return false; } else { long now = System.nanoTime(); TimeUnit.NANOSECONDS.timedWait(lock, nanos); nanos -= System.nanoTime() - now; // subtract the actual time we waited } } } }
/** * Poll for the Nth completed task (index starts from 0 (the 1st), 1 (the second)...) * * @param timeout - time to wait before it times out * @param unit - time unit for timeout * @param index - the index(th) completed task, index starting from 0 */ private QueueingFuture<V> pollForSpecificCompletedTask(long timeout, TimeUnit unit, int index) throws InterruptedException { if (index < 0) { return null; } synchronized (tasks) { if (!cancelled && (completedTasks.size() <= index)) unit.timedWait(tasks, timeout); if (completedTasks.size() <= index) return null; } return completedTasks.get(index); }
@Override public void waitOnObjectUntilNs(Object object, long untilNs) throws InterruptedException { long now = nanoTime(); if (now > untilNs) { //noinspection TIMED_WAIT object.wait(1); } else { TimeUnit.NANOSECONDS.timedWait(object, untilNs - now); } }
private boolean waitUntilDone(long cutoff) throws InterruptedException { boolean hasWait = cutoff != Long.MAX_VALUE; long lastLog = EnvironmentEdgeManager.currentTime(); long currentInProgress; while (0 != (currentInProgress = actionsInProgress.get())) { long now = EnvironmentEdgeManager.currentTime(); if (hasWait && (now * 1000L) > cutoff) { return false; } if (!hasWait) { // Only log if wait is infinite. if (now > lastLog + 10000) { lastLog = now; LOG.info("#" + asyncProcess.id + ", waiting for " + currentInProgress + " actions to finish on table: " + tableName); } } synchronized (actionsInProgress) { if (actionsInProgress.get() == 0) break; if (!hasWait) { actionsInProgress.wait(10); } else { long waitMicroSecond = Math.min(100000L, (cutoff - now * 1000L)); TimeUnit.MICROSECONDS.timedWait(actionsInProgress, waitMicroSecond); } } } return true; }
boolean done = diskStore.checkAndClearForceFlush() || diskStore.checkAsyncItemLimit(); while (!done && nanosRemaining > 0) { TimeUnit.NANOSECONDS.timedWait(diskStore.getAsyncMonitor(), nanosRemaining); done = diskStore.checkAndClearForceFlush() || diskStore.checkAsyncItemLimit(); if (!done) { boolean done = diskStore.checkAndClearForceFlush(); while (!done && nanosRemaining > 0) { TimeUnit.NANOSECONDS.timedWait(diskStore.getAsyncMonitor(), nanosRemaining); done = diskStore.checkAndClearForceFlush(); if (!done) {
throw exeEx; unit.timedWait(tasks, timeout);
@Override public void timedWait(Object lock) throws InterruptedException { unit.timedWait(lock, time); }
TimeUnit.MILLISECONDS.timedWait(this, 500);
/** * Poll for the Nth completed task (index starts from 0 (the 1st), 1 (the second)...) * * @param timeout - time to wait before it times out * @param unit - time unit for timeout * @param index - the index(th) completed task, index starting from 0 */ private QueueingFuture<V> pollForSpecificCompletedTask(long timeout, TimeUnit unit, int index) throws InterruptedException { if (index < 0) { return null; } synchronized (tasks) { if (!cancelled && (completedTasks.size() <= index)) unit.timedWait(tasks, timeout); if (completedTasks.size() <= index) return null; } return completedTasks.get(index); }
TimeUnit.MILLISECONDS.timedWait(this, 500);
private boolean waitUntilDone(long cutoff) throws InterruptedException { boolean hasWait = cutoff != Long.MAX_VALUE; long lastLog = EnvironmentEdgeManager.currentTime(); long currentInProgress; while (0 != (currentInProgress = actionsInProgress.get())) { long now = EnvironmentEdgeManager.currentTime(); if (hasWait && (now * 1000L) > cutoff) { return false; } if (!hasWait) { // Only log if wait is infinite. if (now > lastLog + 10000) { lastLog = now; LOG.info("#" + asyncProcess.id + ", waiting for " + currentInProgress + " actions to finish on table: " + tableName); } } synchronized (actionsInProgress) { if (actionsInProgress.get() == 0) break; if (!hasWait) { actionsInProgress.wait(10); } else { long waitMicroSecond = Math.min(100000L, (cutoff - now * 1000L)); TimeUnit.MICROSECONDS.timedWait(actionsInProgress, waitMicroSecond); } } } return true; }
TimeUnit.MILLISECONDS.timedWait(this, 500);