public static void waitForLatch(CountDownLatch latch, ForeignExceptionSnare monitor,
    long wakeFrequency, String latchDescription) throws ForeignException, InterruptedException {
    boolean released = false;
    while (!released) {
      if (monitor != null) {
        monitor.rethrowException();
      }
      /*
       * ForeignExceptionDispatcher.LOG.debug("Waiting for '" + latchDescription +
       * "' latch. (sleep:" + wakeFrequency + " ms)");
       */
      released = latch.await(wakeFrequency, TimeUnit.MILLISECONDS);
    }
    // check error again in case an error raised during last wait
    if (monitor != null) {
      monitor.rethrowException();
    }
  }
Wait for latch to count to zero, ignoring any spurious wake-ups, but waking periodically to
check for errors
@param latch            latch to wait on
@param monitor          monitor to check for errors while waiting
@param wakeFrequency    frequency to wake up and check for errors (in
                        {@link TimeUnit#MILLISECONDS})
@param latchDescription description of the latch, for logging
@throws ForeignException     type of error the monitor can throw, if the task fails
@throws InterruptedException if we are interrupted while waiting on latch
hbase-server/src/main/java/org/apache/hadoop/hbase/procedure/Procedure.java