diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/core/ClientShutdown.java b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/core/ClientShutdown.java index d22c1697..bf6a148d 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/core/ClientShutdown.java +++ b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/core/ClientShutdown.java @@ -31,7 +31,7 @@ public class ClientShutdown { private CountDownLatch countDownLatch = new CountDownLatch(1); - private final static Long TIME_OUT_SECOND = 5L; + private final static Long TIME_OUT_SECOND = 1L; public void prepareDestroy() throws InterruptedException { prepareClose = true; diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/core/ClientWorker.java b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/core/ClientWorker.java index 570077f7..a5413cfe 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/core/ClientWorker.java +++ b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/core/ClientWorker.java @@ -28,6 +28,7 @@ import cn.hippo4j.springboot.starter.remote.HttpAgent; import cn.hippo4j.springboot.starter.remote.ServerHealthCheck; import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.DisposableBean; import org.springframework.util.StringUtils; import java.net.URLDecoder; @@ -56,7 +57,7 @@ import static cn.hippo4j.common.constant.Constants.WORD_SEPARATOR; * Client worker. */ @Slf4j -public class ClientWorker { +public class ClientWorker implements DisposableBean { private final long timeout; @@ -102,6 +103,11 @@ public class ClientWorker { }, 1L, TimeUnit.MILLISECONDS); } + @Override + public void destroy() throws Exception { + executorService.shutdownNow(); + } + class LongPollingRunnable implements Runnable { private boolean cacheMapInitEmptyFlag; @@ -116,6 +122,9 @@ public class ClientWorker { @Override @SneakyThrows public void run() { + if (executorService.isShutdown()) { + return; + } if (cacheMapInitEmptyFlag) { cacheCondition.await(); cacheMapInitEmptyFlag = false;