mirror of
https://github.com/qaiu/netdisk-fast-download.git
synced 2026-06-10 23:47:29 +00:00
fix: 注册 JVM ShutdownHook,修复 Vert.x 实例进程退出时不关闭的资源泄漏
Deploy.deployVerticle() 中创建的 Vert.x 实例是局部变量,进程退出时无法优雅关闭, 导致 Netty EventLoopGroup、JDBC 连接池、内部定时器等资源泄漏。 添加 ShutdownHook 在 JVM 关闭时调用 vertx.close() 级联释放所有资源。
This commit is contained in:
@@ -43,6 +43,7 @@ public final class Deploy {
|
||||
private Handler<JsonObject> 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<String, Object> localMap = sharedData.getLocalMap(LOCAL);
|
||||
|
||||
Reference in New Issue
Block a user