This is an automated email from the ASF dual-hosted git repository.

jinsongzhou pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/amoro.git


The following commit(s) were added to refs/heads/master by this push:
     new dc1a21a4a [AMORO-3821] The thread pool in PeriodicTableScheduler 
should be gracefully closed (#3822)
dc1a21a4a is described below

commit dc1a21a4a3668e2554b3d3bd401b9f301e8af01a
Author: yl09099 <[email protected]>
AuthorDate: Tue Oct 21 17:37:07 2025 +0800

    [AMORO-3821] The thread pool in PeriodicTableScheduler should be gracefully 
closed (#3822)
    
    [Improvement] [Amoro-3821]: The PeriodicTableScheduler thread is gracefully 
closed.
    
    Co-authored-by: Xu Bai <[email protected]>
---
 .../server/scheduler/PeriodicTableScheduler.java   | 29 +++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)

diff --git 
a/amoro-ams/src/main/java/org/apache/amoro/server/scheduler/PeriodicTableScheduler.java
 
b/amoro-ams/src/main/java/org/apache/amoro/server/scheduler/PeriodicTableScheduler.java
index f08b5110c..5c8554273 100644
--- 
a/amoro-ams/src/main/java/org/apache/amoro/server/scheduler/PeriodicTableScheduler.java
+++ 
b/amoro-ams/src/main/java/org/apache/amoro/server/scheduler/PeriodicTableScheduler.java
@@ -147,10 +147,37 @@ public abstract class PeriodicTableScheduler extends 
RuntimeHandlerChain {
 
   @Override
   protected void doDispose() {
-    executor.shutdownNow();
+
+    gracefulShutdown();
     logger.info("dispose thread pool for threads {}", getThreadName());
   }
 
+  public void gracefulShutdown() {
+    if (executor == null || executor.isShutdown()) {
+      return;
+    }
+
+    try {
+      // Stop accepting new tasks.
+      executor.shutdown();
+
+      // Wait for the current task to complete, with a maximum waiting time of 
30 seconds.
+      if (!executor.awaitTermination(30, TimeUnit.SECONDS)) {
+        // If the timeout occurs, try to cancel the task that is currently 
being executed.
+        executor.shutdownNow();
+
+        // Wait again for the task response to be cancelled.
+        if (!executor.awaitTermination(30, TimeUnit.SECONDS)) {
+          logger.error("The thread pool failed to close properly.");
+        }
+      }
+    } catch (InterruptedException e) {
+      // Re-cancel the interrupt status of the current thread.
+      Thread.currentThread().interrupt();
+      executor.shutdownNow();
+    }
+  }
+
   protected abstract long getExecutorDelay();
 
   protected long getStartDelay() {

Reply via email to