第116批:AI聊天HTTP请求改用独立线程池,不再共用commonPool
Auto Release / build (push) Successful in 1m59s

This commit is contained in:
youpaishidifu
2026-11-11 22:56:50 +08:00
parent da8dae3b5b
commit 2bec4f2252
+17 -2
View File
@@ -121,6 +121,21 @@ public class AIChatManager {
// HTTP Client
private HttpClient httpClient;
// ★ 第116批:AI 聊天专属线程池(与 commonPool/WebManager 隔离)。
// 背景:sendToModel 的 HTTP 请求原本用 CompletableFuture.supplyAsync 跑在
// ForkJoinPool.commonPool,而 commonPool 是 JVM 共享池——一旦被其它任务
//(WebManager 轮询、ForkJoin 任务)占满,AI 请求就要排队等 60 秒窗口耗尽。
// 改为独立有界线程池,AI 请求不再受 commonPool 拥堵影响。
private final java.util.concurrent.ExecutorService aiHttpExecutor =
new java.util.concurrent.ThreadPoolExecutor(2, 4, 60L, java.util.concurrent.TimeUnit.SECONDS,
new java.util.concurrent.LinkedBlockingQueue<>(32),
r -> {
Thread t = new Thread(r, "sdf1-ai-http");
t.setDaemon(true);
return t;
},
new java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy());
// 最近提问的玩家(防止频繁请求)
private final Map<String, Long> lastRequestTime = new ConcurrentHashMap<>();
@@ -1010,7 +1025,7 @@ public class AIChatManager {
plugin.getLogger().warning("[AI聊天-调试] === 请求异常结束 ===");
return null;
}
}).thenAccept(response -> {
}, aiHttpExecutor).thenAccept(response -> {
// ★ 第86批:整个处理体无 try-catch 时,此处任何 RuntimeException
// (最可能是跨线程调用 Bukkit API:player.sendMessage/Bukkit.broadcastMessage)
// 会被 CompletableFuture 链静默吞掉——无日志、无回复、无留档
@@ -2707,7 +2722,7 @@ public class AIChatManager {
plugin.getLogger().warning("[AI聊天-调试] === 自动互动请求异常结束 ===");
return null;
}
}).thenAccept(response -> {
}, aiHttpExecutor).thenAccept(response -> {
if (response == null) {
plugin.getLogger().warning("[AI聊天-调试] 自动互动请求失败: 网络异常/超时");
plugin.getLogger().warning("[AI聊天-调试] 模型全名: " + defaultModelFull);