mirror of
https://github.com/qaiu/netdisk-fast-download.git
synced 2026-06-11 07:57:28 +00:00
fix: JsParserExecutor 和 JsHttpClient 添加资源清理,修复解析完成后资源泄漏
- JsHttpClient 添加 close() 方法释放 WebClient 连接池 - JsParserExecutor 添加 close() 方法,清除 ScriptEngine 中注入的 Java 对象引用 - parse()/parseFileList()/parseById() 均在 onComplete 回调中调用 close() 释放资源
This commit is contained in:
@@ -61,7 +61,7 @@ public class JsHttpClient {
|
||||
};
|
||||
|
||||
public JsHttpClient() {
|
||||
this.client = WebClient.create(WebClientVertxInit.get(), new WebClientOptions());;
|
||||
this.client = WebClient.create(WebClientVertxInit.get(), new WebClientOptions());
|
||||
this.clientSession = WebClientSession.create(client);
|
||||
this.headers = MultiMap.caseInsensitiveMultiMap();
|
||||
// 设置默认的Accept-Encoding头以支持压缩响应
|
||||
@@ -677,4 +677,13 @@ public class JsHttpClient {
|
||||
return buffer.length();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭 WebClient 释放连接池资源
|
||||
*/
|
||||
public void close() {
|
||||
if (client != null) {
|
||||
client.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,6 +146,22 @@ public class JsParserExecutor implements IPanTool {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 释放资源(ScriptEngine 和 HttpClient),避免内存泄漏
|
||||
*/
|
||||
public void close() {
|
||||
if (httpClient != null) {
|
||||
httpClient.close();
|
||||
}
|
||||
// 清除 ScriptEngine 持有的 Java 对象引用,帮助 GC 回收
|
||||
if (engine != null) {
|
||||
engine.put("http", null);
|
||||
engine.put("logger", null);
|
||||
engine.put("shareLinkInfo", null);
|
||||
engine.put("JavaFetch", null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Future<String> parse() {
|
||||
jsLogger.info("开始执行JavaScript解析器: {}", config.getType());
|
||||
@@ -173,7 +189,7 @@ public class JsParserExecutor implements IPanTool {
|
||||
} else {
|
||||
throw new RuntimeException("parse函数类型错误");
|
||||
}
|
||||
});
|
||||
}).onComplete(ar -> close());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -206,7 +222,7 @@ public class JsParserExecutor implements IPanTool {
|
||||
} else {
|
||||
throw new RuntimeException("parseFileList函数类型错误");
|
||||
}
|
||||
});
|
||||
}).onComplete(ar -> close());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -237,7 +253,7 @@ public class JsParserExecutor implements IPanTool {
|
||||
} else {
|
||||
throw new RuntimeException("parseById函数类型错误");
|
||||
}
|
||||
});
|
||||
}).onComplete(ar -> close());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user