/** For testing: waits until {@code requiredPongCount} pings have been received from the peer. */ synchronized void awaitPong() throws InterruptedException { while (awaitingPong) { wait(); } }
Object mon = ...; synchronized (mon) { mon.wait(); }
/** * Blocks until the event becomes the signaled state. * * <p> * This method blocks infinitely until a value is offered. */ public void block() throws InterruptedException { synchronized (lock) { while(!signaled) lock.wait(); } }
synchronized R await() throws InterruptedException, ExecutionException { while (true) { if (exception != null) wrapAndThrow(exception); if (done) return value; this.wait(); } }
/** * Like {@link #wait}, but throws an {@code InterruptedIOException} when interrupted instead of * the more awkward {@link InterruptedException}. */ void waitForIo() throws InterruptedIOException { try { wait(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); // Retain interrupted status. throw new InterruptedIOException(); } }
@Override public void lock() { synchronized (globalMutex) { // Wait until the lock is free. while (!isLockFree()) { try { globalMutex.wait(); } catch (InterruptedException e) { LOGGER.info("InterruptedException while waiting for globalMutex to begin writing", e); Thread.currentThread().interrupt(); } } // When the lock is free, acquire it by placing an entry in globalMutex globalMutex.add(this); } }
/** * Acquire the globalMutex lock on behalf of current and future concurrent readers. Make sure no writers currently * owns the lock. */ private void acquireForReaders() { // Try to get the globalMutex lock for the first reader synchronized (globalMutex) { // If the no one get the lock or the lock is locked by reader, just set the reference // to the globalMutex to indicate that the lock is locked by Reader. while (doesWriterOwnThisLock()) { try { globalMutex.wait(); } catch (InterruptedException e) { LOGGER.info("InterruptedException while waiting for globalMutex in acquireForReaders", e); Thread.currentThread().interrupt(); } } globalMutex.add(this); } }
public void doWait() { this.counter++; // wait until stop is called synchronized (this.lock) { try { this.lock.wait(); } catch (InterruptedException e) { // fall through } } }
private static boolean test() { try { synchronized (obj) { obj.wait(5); } return true; } catch (InterruptedException e) { return false; } } }
void destroy () { synchronized (synch) { running = false; destroy = true; while (destroy) { try { synch.wait(); } catch (InterruptedException ex) { Gdx.app.log(LOG_TAG, "waiting for destroy synchronization failed!"); } } } }
public void waitUntilOffline() throws InterruptedException { synchronized (statusChangeLock) { while (!isOffline()) statusChangeLock.wait(1000); } }
void destroy () { synchronized (synch) { running = false; destroy = true; while (destroy) { try { synch.wait(); } catch (InterruptedException ex) { Gdx.app.log(LOG_TAG, "waiting for destroy synchronization failed!"); } } } }
/** * Blocks until the node becomes online/offline. */ public void waitUntilOnline() throws InterruptedException { synchronized (statusChangeLock) { while (!isOnline()) statusChangeLock.wait(1000); } }
private void executeAndWait(SimpleAsyncTaskExecutor executor, Runnable task, Object monitor) { synchronized (monitor) { executor.execute(task); try { monitor.wait(); } catch (InterruptedException ignored) { } } }
public synchronized void waitForCompletion() { try { wait(WAIT_TIME); } catch (InterruptedException ex) { fail("Didn't finish the async job in " + WAIT_TIME + " milliseconds"); } } }
@Override public void doSubscribe(URL url, NotifyListener listener) { if (Constants.ANY_VALUE.equals(url.getServiceInterface())) { admin = true; } multicast(Constants.SUBSCRIBE + " " + url.toFullString()); synchronized (listener) { try { listener.wait(url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT)); } catch (InterruptedException e) { } } }
@Override public void doSubscribe(URL url, NotifyListener listener) { if (Constants.ANY_VALUE.equals(url.getServiceInterface())) { admin = true; } multicast(Constants.SUBSCRIBE + " " + url.toFullString()); synchronized (listener) { try { listener.wait(url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT)); } catch (InterruptedException e) { } } }
@Override public void run() { try { while (!shutdown) { synchronized (this) { wait(HTTPCLIENTCONNECTIONMANAGER_CLOSEWAITTIME_MS); for (PoolingHttpClientConnectionManager connectionManager : connectionManagers) { connectionManager.closeExpiredConnections(); connectionManager.closeIdleConnections(HTTPCLIENTCONNECTIONMANAGER_CLOSEIDLETIME_S, TimeUnit.SECONDS); } } } } catch (InterruptedException ex) { shutdown(); } }
@Override public void run() { try { while (!shutdown) { synchronized (this) { wait(HTTPCLIENTCONNECTIONMANAGER_CLOSEWAITTIME_MS); for (PoolingHttpClientConnectionManager connectionManager : connectionManagers) { connectionManager.closeExpiredConnections(); connectionManager.closeIdleConnections(HTTPCLIENTCONNECTIONMANAGER_CLOSEIDLETIME_S, TimeUnit.SECONDS); } } } } catch (InterruptedException ex) { shutdown(); } }
private synchronized void maybeAwaitWakeup() { try { int remainingBlockingWakeups = numBlockingWakeups; if (remainingBlockingWakeups <= 0) return; while (numBlockingWakeups == remainingBlockingWakeups) wait(); } catch (InterruptedException e) { throw new InterruptException(e); } }