@Override
  public void run() {
    DriverTask next;
    try {
      while (!closed && !Thread.currentThread().isInterrupted()) {
        try {
          next = queue.poll();
        } catch (InterruptedException e) {
          logger.warn("Executor {} failed to poll driver task from queue", this.getName());
          Thread.currentThread().interrupt();
          break;
        }

        if (next == null) {
          logger.error("DriverTask should never be null");
          continue;
        }

        try (SetThreadName driverTaskName = new SetThreadName(next.getDriverTaskId().getFullId())) {
          execute(next);
        } catch (Exception e) {
          // Try-with-resource syntax will call close once after try block is done, so we need to
          // reset the thread name here
          try (SetThreadName driverTaskName =
              new SetThreadName(next.getDriver().getDriverTaskId().getFullId())) {
            Throwable rootCause = ErrorHandlingUtils.getRootCause(e);
            if (rootCause instanceof IoTDBRuntimeException) {
              next.setAbortCause(rootCause);
            } else if (rootCause instanceof IoTDBException) {
              next.setAbortCause(rootCause);
            } else if (rootCause instanceof DateTimeParseException) {
              next.setAbortCause(
                  new IoTDBRuntimeException(
                      rootCause.getMessage(), DATE_OUT_OF_RANGE.getStatusCode(), true));
            } else {
              logger.warn("[ExecuteFailed]", rootCause);
              next.setAbortCause(
                  new DriverTaskAbortedException(
                      next.getDriverTaskId().getFullId(),
                      DriverTaskAbortedException.BY_INTERNAL_ERROR_SCHEDULED));
            }
            scheduler.toAborted(next);
          }
        } finally {
          // Clear the interrupted flag on the current thread, driver cancellation may have
          // triggered an interrupt
          if (Thread.interrupted() && closed) {
            // Reset interrupted flag if closed before interrupt
            Thread.currentThread().interrupt();
          }
        }
      }
    } finally {
      // Unless we have been closed, we need to replace this thread
      if (!closed) {
        logger.warn(
            "Executor {} exits because it's interrupted. We will produce another thread to replace.",
            this.getName());
        producer.produce(getName(), getThreadGroup(), queue, producer);
      } else {
        logger.info("Executor {} exits because it is closed.", this.getName());
      }
    }
  }
An abstract executor for {@link DriverTask}.
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/schedule/AbstractDriverThread.java