diff --git a/core/src/main/java/org/dromara/dynamictp/core/monitor/DtpMonitor.java b/core/src/main/java/org/dromara/dynamictp/core/monitor/DtpMonitor.java index 6fa267c60..ba4395e18 100644 --- a/core/src/main/java/org/dromara/dynamictp/core/monitor/DtpMonitor.java +++ b/core/src/main/java/org/dromara/dynamictp/core/monitor/DtpMonitor.java @@ -50,7 +50,7 @@ @Slf4j public class DtpMonitor { - private static final ScheduledExecutorService MONITOR_EXECUTOR = ThreadPoolCreator.newScheduledThreadPool("dtp-monitor", 1); + private static ScheduledExecutorService MONITOR_EXECUTOR; private final DtpProperties dtpProperties; @@ -73,6 +73,9 @@ public synchronized void onContextRefreshedEvent(CustomContextRefreshedEvent eve if (monitorFuture != null) { monitorFuture.cancel(true); } + if (MONITOR_EXECUTOR == null || MONITOR_EXECUTOR.isShutdown() || MONITOR_EXECUTOR.isTerminated()) { + MONITOR_EXECUTOR = ThreadPoolCreator.newScheduledThreadPool("dtp-monitor", 1); + } monitorInterval = dtpProperties.getMonitorInterval(); monitorFuture = MONITOR_EXECUTOR.scheduleWithFixedDelay(this::run, 0, dtpProperties.getMonitorInterval(), TimeUnit.SECONDS);