public void awaitShutdown() throws InterruptedException {
        if (!isShutdownInitiated())
            throw new IllegalStateException("initiateShutdown() was not called before awaitShutdown()");
        else {
            if (isStarted)
                shutdownComplete.await();
            log.info("Shutdown completed");
        }
    }
After calling initiateShutdown(), use this API to wait until the shutdown is complete.
server-common/src/main/java/org/apache/kafka/server/util/ShutdownableThread.java