diff --git a/core/src/main/java/cn/qaiu/vx/core/Deploy.java b/core/src/main/java/cn/qaiu/vx/core/Deploy.java index e6717be..0775c9f 100644 --- a/core/src/main/java/cn/qaiu/vx/core/Deploy.java +++ b/core/src/main/java/cn/qaiu/vx/core/Deploy.java @@ -43,6 +43,7 @@ public final class Deploy { private Handler handle; private Thread mainThread; + private Vertx mainVertx; public static Deploy instance() { return INSTANCE; @@ -137,6 +138,14 @@ public final class Deploy { vertxOptions.getWorkerPoolSize()); var vertx = Vertx.vertx(vertxOptions); VertxHolder.init(vertx); + this.mainVertx = vertx; + + // 注册 ShutdownHook,确保进程退出时优雅关闭资源 + Runtime.getRuntime().addShutdownHook(new Thread(() -> { + LOGGER.info("JVM shutting down, closing Vert.x..."); + vertx.close().onComplete(ar -> + LOGGER.info("Vert.x closed: {}", ar.succeeded() ? "success" : ar.cause().getMessage())); + })); //配置保存在共享数据中 var sharedData = vertx.sharedData(); LocalMap localMap = sharedData.getLocalMap(LOCAL);