From 2cb17fc7a9e2bda2ef2b8a528bb8cf580e9f0ae4 Mon Sep 17 00:00:00 2001 From: liusen Date: Sat, 24 Aug 2024 23:31:42 +0800 Subject: [PATCH 1/5] Wait for all close method to be completed before destroying the thread. Such as after calling gracefulShutdown in the close method of TomcatWebServer --- .../dynamictp/core/spring/DtpLifecycle.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/org/dromara/dynamictp/core/spring/DtpLifecycle.java b/core/src/main/java/org/dromara/dynamictp/core/spring/DtpLifecycle.java index 3a6af1bd9..9d73b9d01 100644 --- a/core/src/main/java/org/dromara/dynamictp/core/spring/DtpLifecycle.java +++ b/core/src/main/java/org/dromara/dynamictp/core/spring/DtpLifecycle.java @@ -24,6 +24,7 @@ import org.dromara.dynamictp.core.notifier.manager.NoticeManager; import org.dromara.dynamictp.core.support.DtpLifecycleSupport; import org.dromara.dynamictp.core.system.SystemMetricManager; +import org.springframework.beans.factory.DisposableBean; import org.springframework.context.SmartLifecycle; import java.util.concurrent.atomic.AtomicBoolean; @@ -35,7 +36,7 @@ * @since 1.1.3 **/ @Slf4j -public class DtpLifecycle implements SmartLifecycle { +public class DtpLifecycle implements SmartLifecycle, DisposableBean { private final AtomicBoolean running = new AtomicBoolean(false); @@ -48,10 +49,6 @@ public void start() { @Override public void stop() { - if (this.running.compareAndSet(true, false)) { - shutdownInternal(); - DtpRegistry.getAllExecutors().forEach((k, v) -> DtpLifecycleSupport.destroy(v)); - } } @Override @@ -90,10 +87,19 @@ public int getPhase() { return Integer.MAX_VALUE; } + @Override + public void destroy() throws Exception { + if (this.running.compareAndSet(true, false)) { + shutdownInternal(); + DtpRegistry.getAllExecutors().forEach((k, v) -> DtpLifecycleSupport.destroy(v)); + } + } + public void shutdownInternal() { DtpMonitor.destroy(); AlarmManager.destroy(); NoticeManager.destroy(); SystemMetricManager.stop(); } + } From 91ec59282c12178a256aeddf1863b42b21abeca0 Mon Sep 17 00:00:00 2001 From: liusen Date: Sun, 25 Aug 2024 00:07:14 +0800 Subject: [PATCH 2/5] Reduce phase,Close later --- .../java/org/dromara/dynamictp/core/spring/DtpLifecycle.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/dromara/dynamictp/core/spring/DtpLifecycle.java b/core/src/main/java/org/dromara/dynamictp/core/spring/DtpLifecycle.java index 9d73b9d01..933f9a3f4 100644 --- a/core/src/main/java/org/dromara/dynamictp/core/spring/DtpLifecycle.java +++ b/core/src/main/java/org/dromara/dynamictp/core/spring/DtpLifecycle.java @@ -84,7 +84,7 @@ public boolean isAutoStartup() { */ @Override public int getPhase() { - return Integer.MAX_VALUE; + return Integer.MAX_VALUE -1; } @Override From ccbf274de145a6a2bdf9cbbaf266b235146f8277 Mon Sep 17 00:00:00 2001 From: intechsen <313769823@qq.com> Date: Sun, 25 Aug 2024 00:28:35 +0800 Subject: [PATCH 3/5] Revert "Reduce phase,Close later" This reverts commit 91ec59282c12178a256aeddf1863b42b21abeca0. --- .../java/org/dromara/dynamictp/core/spring/DtpLifecycle.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/dromara/dynamictp/core/spring/DtpLifecycle.java b/core/src/main/java/org/dromara/dynamictp/core/spring/DtpLifecycle.java index 933f9a3f4..9d73b9d01 100644 --- a/core/src/main/java/org/dromara/dynamictp/core/spring/DtpLifecycle.java +++ b/core/src/main/java/org/dromara/dynamictp/core/spring/DtpLifecycle.java @@ -84,7 +84,7 @@ public boolean isAutoStartup() { */ @Override public int getPhase() { - return Integer.MAX_VALUE -1; + return Integer.MAX_VALUE; } @Override From bc5d797d87eebae585b9ca3a524fa98e5e9825b9 Mon Sep 17 00:00:00 2001 From: intechsen <313769823@qq.com> Date: Sun, 25 Aug 2024 00:28:45 +0800 Subject: [PATCH 4/5] Revert "Wait for all close method to be completed before destroying the thread. Such as after calling gracefulShutdown in the close method of TomcatWebServer" This reverts commit 2cb17fc7a9e2bda2ef2b8a528bb8cf580e9f0ae4. --- .../dynamictp/core/spring/DtpLifecycle.java | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/core/src/main/java/org/dromara/dynamictp/core/spring/DtpLifecycle.java b/core/src/main/java/org/dromara/dynamictp/core/spring/DtpLifecycle.java index 9d73b9d01..3a6af1bd9 100644 --- a/core/src/main/java/org/dromara/dynamictp/core/spring/DtpLifecycle.java +++ b/core/src/main/java/org/dromara/dynamictp/core/spring/DtpLifecycle.java @@ -24,7 +24,6 @@ import org.dromara.dynamictp.core.notifier.manager.NoticeManager; import org.dromara.dynamictp.core.support.DtpLifecycleSupport; import org.dromara.dynamictp.core.system.SystemMetricManager; -import org.springframework.beans.factory.DisposableBean; import org.springframework.context.SmartLifecycle; import java.util.concurrent.atomic.AtomicBoolean; @@ -36,7 +35,7 @@ * @since 1.1.3 **/ @Slf4j -public class DtpLifecycle implements SmartLifecycle, DisposableBean { +public class DtpLifecycle implements SmartLifecycle { private final AtomicBoolean running = new AtomicBoolean(false); @@ -49,6 +48,10 @@ public void start() { @Override public void stop() { + if (this.running.compareAndSet(true, false)) { + shutdownInternal(); + DtpRegistry.getAllExecutors().forEach((k, v) -> DtpLifecycleSupport.destroy(v)); + } } @Override @@ -87,19 +90,10 @@ public int getPhase() { return Integer.MAX_VALUE; } - @Override - public void destroy() throws Exception { - if (this.running.compareAndSet(true, false)) { - shutdownInternal(); - DtpRegistry.getAllExecutors().forEach((k, v) -> DtpLifecycleSupport.destroy(v)); - } - } - public void shutdownInternal() { DtpMonitor.destroy(); AlarmManager.destroy(); NoticeManager.destroy(); SystemMetricManager.stop(); } - } From 6a106c3c87a65c5c9406ab94efd071b635f15926 Mon Sep 17 00:00:00 2001 From: intechsen <313769823@qq.com> Date: Sun, 25 Aug 2024 00:30:50 +0800 Subject: [PATCH 5/5] Wait for all close method to be completed before destroying the thread. Such as after calling gracefulShutdown in the close method of TomcatWebServer. And reduce phase Close later --- .../dynamictp/core/spring/DtpLifecycle.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/org/dromara/dynamictp/core/spring/DtpLifecycle.java b/core/src/main/java/org/dromara/dynamictp/core/spring/DtpLifecycle.java index 3a6af1bd9..e17370276 100644 --- a/core/src/main/java/org/dromara/dynamictp/core/spring/DtpLifecycle.java +++ b/core/src/main/java/org/dromara/dynamictp/core/spring/DtpLifecycle.java @@ -24,6 +24,7 @@ import org.dromara.dynamictp.core.notifier.manager.NoticeManager; import org.dromara.dynamictp.core.support.DtpLifecycleSupport; import org.dromara.dynamictp.core.system.SystemMetricManager; +import org.springframework.beans.factory.DisposableBean; import org.springframework.context.SmartLifecycle; import java.util.concurrent.atomic.AtomicBoolean; @@ -35,7 +36,7 @@ * @since 1.1.3 **/ @Slf4j -public class DtpLifecycle implements SmartLifecycle { +public class DtpLifecycle implements SmartLifecycle, DisposableBean { private final AtomicBoolean running = new AtomicBoolean(false); @@ -48,10 +49,6 @@ public void start() { @Override public void stop() { - if (this.running.compareAndSet(true, false)) { - shutdownInternal(); - DtpRegistry.getAllExecutors().forEach((k, v) -> DtpLifecycleSupport.destroy(v)); - } } @Override @@ -87,7 +84,15 @@ public boolean isAutoStartup() { */ @Override public int getPhase() { - return Integer.MAX_VALUE; + return Integer.MAX_VALUE -1; + } + + @Override + public void destroy() throws Exception { + if (this.running.compareAndSet(true, false)) { + shutdownInternal(); + DtpRegistry.getAllExecutors().forEach((k, v) -> DtpLifecycleSupport.destroy(v)); + } } public void shutdownInternal() {