@Override
    public Boolean call() throws Exception {
      // Heartbeat only for active tasks. Errors, etc will be reported directly.
      while (!task.isTaskDone() && !task.wasErrorReported()) {
        ResponseWrapper response = heartbeat(null);

        if (response.shouldDie) {
          // AM sent a shouldDie=true
          LOG.info("Asked to die via task heartbeat: {}", task.getTaskAttemptID());
          return false;
        } else {
          if (response.numEvents < maxEventsToGet) {
            // Wait before sending another heartbeat. Otherwise consider as an OOB heartbeat
            lock.lock();
            try {
              boolean interrupted = condition.await(pollInterval, TimeUnit.MILLISECONDS);
              if (!interrupted) {
                nonOobHeartbeatCounter.incrementAndGet();
              }
            } finally {
              lock.unlock();
            }
          }
        }
      }
      int pendingEventCount = eventsToSend.size();
      if (pendingEventCount > 0) {
        // This is OK because the pending events will be sent via the succeeded/failed messages.
        // TaskDone is set before taskSucceeded/taskTerminated are sent out - which is what causes the
        // thread to exit
        LOG.warn("Exiting TaskReporter thread with pending queue size=" + pendingEventCount);
      }
      return true;
    }
This method should always be invoked before setting up heartbeats for another task running in
the same container.
llap-server/src/java/org/apache/hadoop/hive/llap/daemon/impl/LlapTaskReporter.java