@Override
  public synchronized void setCapacity(int newNumExecutors, int newWaitQueueSize) {
    if (newNumExecutors > configuredMaxExecutors) {
      throw new IllegalArgumentException("Requested newNumExecutors=" + newNumExecutors
          + " is greater than the configured maximum=" + configuredMaxExecutors);
    }
    if (newWaitQueueSize > configuredWaitingQueueSize) {
      throw new IllegalArgumentException("Requested newWaitQueueSize=" + newWaitQueueSize
          + " is greater than the configured maximum=" + configuredWaitingQueueSize);
    }
    if (newNumExecutors < 0) {
      throw new IllegalArgumentException("Negative numExecutors is not allowed. Requested "
          + "newNumExecutors=" + newNumExecutors);
    }
    if (newWaitQueueSize < 0) {
      throw new IllegalArgumentException("Negative waitQueueSize is not allowed. Requested "
          + "newWaitQueueSize=" + newWaitQueueSize);
    }
    numSlotsAvailable.addAndGet(newNumExecutors - maxParallelExecutors);
    maxParallelExecutors = newNumExecutors;
    waitQueue.setWaitQueueSize(newWaitQueueSize);
    metrics.setNumExecutors(newNumExecutors);
    metrics.setWaitQueueSize(newWaitQueueSize);
    // If there is no executor left so the queued tasks can not be finished anyway, kill them all.
    if (newNumExecutors == 0) {
      synchronized (lock) {
        TaskWrapper task = waitQueue.peek();
        while (task != null) {
          LOG.info("Killing task [" + task + "], since no executor left.");
          task.getTaskRunnerCallable().killTask();
          if (waitQueue.remove(task)) {
            metrics.setExecutorNumQueuedRequests(waitQueue.size());
          }
          task = waitQueue.peek();
        }
      }
    }
    LOG.info("TaskExecutorService is setting capacity to: numExecutors=" + newNumExecutors
        + ", waitQueueSize=" + newWaitQueueSize);
  }
Sets the TaskExecutorService capacity to the new values. Both the number of executors and the
queue size should be smaller than that original values, so we do not mess up with the other
settings. (For example: We do not allow higher executor number which could cause memory
oversubscription since the container memory sizes are calculated based on the maximum memory
and the maximum number of executors)
Setting smaller capacity will not cancel or reject already executing or queued tasks in itself.
@param newNumExecutors The new number of executors
@param newWaitQueueSize The new number of wait queue size
llap-server/src/java/org/apache/hadoop/hive/llap/daemon/impl/TaskExecutorService.java