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() {