private synchronized void stopHeartbeat() {
    if (heartbeatTask != null) {
      heartbeatTask.cancel(true);
      
      long startTime = System.currentTimeMillis();
      long sleepInterval = 100;
      
      while (!heartbeatTask.isCancelled() && !heartbeatTask.isDone()) {
        // We will wait for 30 seconds for the task to be cancelled.
        // If it's still not cancelled (unlikely), we will just move on.
        long now = System.currentTimeMillis();
        if (now - startTime > 30000) {
          LOG.error("Heartbeat task cannot be cancelled for unknown reason. QueryId: " + queryId);
          break;
        }
        try {
          Thread.sleep(sleepInterval);
        } catch (InterruptedException e) {
        }
        sleepInterval *= 2;
      }
      if (heartbeatTask.isCancelled() || heartbeatTask.isDone()) {
        LOG.info("Stopped heartbeat for query: " + queryId);
      }
      heartbeatTask = null;
      queryId = null;
    }
  }
Start the heartbeater threadpool and return the task.
@param initialDelay time to delay before first execution, in milliseconds
@return heartbeater
ql/src/java/org/apache/hadoop/hive/ql/lockmgr/DbTxnManager.java