private synchronized boolean waitForWork() {
    // beware of the concurrent access to the calls list: we can add calls, but as well
    // remove them.
    long waitUntil = EnvironmentEdgeManager.currentTime() + this.rpcClient.minIdleTimeBeforeClose;
    for (;;) {
      if (thread == null) {
        return false;
      }
      if (!calls.isEmpty()) {
        return true;
      }
      if (EnvironmentEdgeManager.currentTime() >= waitUntil) {
        closeConn(
          new IOException("idle connection closed with " + calls.size() + " pending request(s)"));
        return false;
      }
      try {
        wait(Math.min(this.rpcClient.minIdleTimeBeforeClose, 1000));
      } catch (InterruptedException e) {
        // Restore interrupt status
        Thread.currentThread().interrupt();
      }
    }
  }
Handle connection failures If the current number of retries is equal to the max number of
retries, stop retrying and throw the exception; Otherwise backoff N seconds and try connecting
again. This Method is only called from inside setupIOstreams(), which is synchronized. Hence
the sleep is synchronized; the locks will be retained.
@param curRetries current number of retries
@param maxRetries max number of retries allowed
@param ioe        failure reason
@throws IOException if max number of retries is reached
hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/BlockingRpcConnection.java