diff --git a/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/iot/logdispatcher/LogDispatcher.java b/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/iot/logdispatcher/LogDispatcher.java index a62bdd4e1320..6b33fcc5dfc3 100644 --- a/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/iot/logdispatcher/LogDispatcher.java +++ b/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/iot/logdispatcher/LogDispatcher.java @@ -104,7 +104,8 @@ public synchronized void start() { public synchronized void stop() { if (!threads.isEmpty()) { - threads.forEach(LogDispatcherThread::stop); + threads.forEach(LogDispatcherThread::setStopped); + threads.forEach(LogDispatcherThread::processStopped); executorService.shutdownNow(); int timeout = 10; try { @@ -300,7 +301,15 @@ private void releaseReservedMemory(IndexedConsensusRequest indexedConsensusReque } public void stop() { + setStopped(); + processStopped(); + } + + private void setStopped() { stopped = true; + } + + private void processStopped() { try { if (!runFinished.await(30, TimeUnit.SECONDS)) { logger.info("{}: Dispatcher for {} didn't stop after 30s.", impl.getThisNode(), peer);