@Override
  public synchronized void stop() {
    LOG.info("Shutting down HiveServer2");
    HiveConf hiveConf = this.getHiveConf();
    super.stop();
    if (scheduledQueryService != null) {
      try {
        scheduledQueryService.close();
      } catch (Exception e) {
        LOG.error("Error stopping schq", e);
      }
    }
    if (queryHistoryService != null) {
      try {
        LOG.info("Calling QueryHistoryService.close from HiveServer2.stop");
        queryHistoryService.stop();
      } catch (Exception e) {
        LOG.error("Error stopping queryHistoryService", e);
      }
    }
    //Shutdown metric collection
    MetricSink.getInstance().tearDown();
    if (hs2HARegistry != null) {
      hs2HARegistry.stop();
      shutdownExecutor(leaderActionsExecutorService);
      LOG.info("HS2 HA registry stopped");
      hs2HARegistry = null;
    }
    if (webServer != null) {
      try {
        webServer.stop();
        LOG.info("Web UI has stopped");
      } catch (Exception e) {
        LOG.error("Error stopping Web UI: ", e);
      }
    }
    // Shutdown Metrics
    if (MetricsFactory.getInstance() != null) {
      try {
        MetricsFactory.close();
      } catch (Exception e) {
        LOG.error("error in Metrics deinit: " + e.getClass().getName() + " "
          + e.getMessage(), e);
      }
    }
    // Remove this server instance from ZooKeeper if dynamic service discovery is set
    if (serviceDiscovery && !activePassiveHA) {
      try {
        if (zooKeeperHelper != null) {
          zooKeeperHelper.removeServerInstanceFromZooKeeper();
        }
      } catch (Exception e) {
        LOG.error("Error removing znode for this HiveServer2 instance from ZooKeeper.", e);
      }
    }

    stopOrDisconnectTezSessions();

    if (zKClientForPrivSync != null) {
      zKClientForPrivSync.close();
    }
    if (hiveConf != null && AuthType.isSamlAuthMode(hiveConf)) {
      // this is mostly for testing purposes to make sure that SAML client is
      // reinitialized after a HS2 is restarted.
      HiveSaml2Client.shutdown();
    }

    if (otelExporter != null) {
      otelExporter.interrupt();
    }

  }
Decommission HiveServer2. As a consequence, SessionManager stops
opening new sessions, OperationManager refuses running new queries and
HiveServer2 deregisters itself from Zookeeper if service discovery is enabled,
but the decommissioning has no effect on the current running queries.
service/src/java/org/apache/hive/service/server/HiveServer2.java