/** * Await without interruption. In the case of interruption, log a warning and continue to wait. */ public void awaitUninterruptibly() { while (true) { try { await(); return; } catch (final InterruptedException e) { // if we're still not ready, the while loop will cause us to wait again logger.warn("Interrupted while waiting for event latch.", e); } } } }
@Override public void await() throws InterruptedException { Preconditions.checkNotNull(latch, "Latch not initialized in %s at %s.", siteClass.getSimpleName(), desc); try { latch.await(); } catch (final InterruptedException e) { logger.warn("Interrupted while awaiting in {} at {}.", siteClass.getSimpleName(), desc); throw e; } }
public void interruptiblePause() throws InterruptedException { if (!injectNow()) { return; } latch.await(); }
/** * Await without interruption for a given time. * @param waitMillis * Time in milliseconds to wait * @return Whether the countdown reached zero or not. */ public boolean awaitUninterruptibly(long waitMillis) { final long targetMillis = System.currentTimeMillis() + waitMillis; while (System.currentTimeMillis() < targetMillis) { final long wait = targetMillis - System.currentTimeMillis(); if (wait < 1) { return false; } try { return await(wait, TimeUnit.MILLISECONDS); } catch (final InterruptedException e) { // if we weren't ready, the while loop will continue to wait } } return false; }