/**
   * Updates each ThreadPoolExecutor with the current time, which is the time when a context is
   * being stopped.
   *
   * @param context the context being stopped, used to discover all the Connectors of its parent
   *     Service.
   */
  public void stopIdleThreads(Context context) throws RemoteException, RemoteException {
    if (serverStopping) return;

    if (!(context instanceof StandardContextRemoteInterface)
        || !((StandardContextRemoteInterface) context).getRenewThreadsWhenStoppingContext()) {
      log.debug(
          "Not renewing threads when the context is stopping. " + "It is not configured to do it.");
      return;
    }

    Engine engine = (Engine) context.getParent().getParent();
    Service service = engine.getService();
    ConnectorRemoteInterface[] connectors = service.findConnectors();
    if (connectors != null) {
      for (ConnectorRemoteInterface connector : connectors) {
        ProtocolHandler handler = connector.getProtocolHandler();
        Executor executor = null;
        if (handler != null) {
          executor = handler.getExecutor();
        }

        if (executor instanceof ThreadPoolExecutor2RemoteInterface) {
          ThreadPoolExecutor2RemoteInterface threadPoolExecutor =
              (ThreadPoolExecutor2RemoteInterface) executor;
          threadPoolExecutor.contextStopping();
        } else if (executor instanceof StandardThreadExecutorRemoteInterface) {
          StandardThreadExecutorRemoteInterface stdThreadExecutor =
              (StandardThreadExecutorRemoteInterface) executor;
          stdThreadExecutor.contextStopping();
        }
      }
    }
  }