From 3c085e086ddcc7f2c0466065837a9f9f5d095b62 Mon Sep 17 00:00:00 2001 From: youpaishidifu Date: Thu, 25 Jun 2026 00:49:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96:=20=E5=85=A8=E9=87=8F?= =?UTF-8?q?=E5=90=8C=E6=AD=A5=E4=BB=BB=E5=8A=A1=E9=97=B4=E9=94=99=E5=BC=80?= =?UTF-8?q?800ms=E6=89=A7=E8=A1=8C=EF=BC=8C=E9=81=BF=E5=85=8D=E7=9E=AC?= =?UTF-8?q?=E9=97=B4=E5=A0=86=E5=8F=A0=E5=AF=BC=E8=87=B4DB=E9=98=9F?= =?UTF-8?q?=E5=88=97=E7=AD=89=E5=BE=85=E8=BF=87=E4=B9=85=E5=92=8CHTTP=2040?= =?UTF-8?q?4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Sdf1_login/WebManager.java | 43 +++++++++++++++++++++--- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/src/main/java/Sdf1_login/WebManager.java b/src/main/java/Sdf1_login/WebManager.java index f439dc7..82e7a00 100644 --- a/src/main/java/Sdf1_login/WebManager.java +++ b/src/main/java/Sdf1_login/WebManager.java @@ -794,21 +794,31 @@ public class WebManager { cleanExpiredTokens(); // ★ 启动后延迟30秒执行首次全量同步(通过DB队列串行化) + // 每个任务之间加入随机延迟,避免瞬时堆叠导致DB队列等待过久 new BukkitRunnable() { @Override public void run() { plugin.getLogger().info("[Web通信] 开始首次全量同步(通过DB队列串行化)..."); // 登录相关操作高优先级 submitDbTask("首次-syncUserRegistrations", () -> syncUserRegistrations()); + try { Thread.sleep(800); } catch (InterruptedException ignored) {} submitDbTask("首次-pushWebLoginCredentials", () -> pushWebLoginCredentials()); - // 普通同步操作低优先级 + try { Thread.sleep(800); } catch (InterruptedException ignored) {} + // 普通同步操作低优先级(每个任务间错开800ms) submitNormalDbTask("首次-syncOnlinePlayers", () -> syncOnlinePlayers()); + try { Thread.sleep(800); } catch (InterruptedException ignored) {} submitNormalDbTask("首次-syncShopData", () -> syncShopData()); + try { Thread.sleep(800); } catch (InterruptedException ignored) {} submitNormalDbTask("首次-syncBondBalances", () -> syncBondBalances()); + try { Thread.sleep(800); } catch (InterruptedException ignored) {} submitNormalDbTask("首次-syncBondTransactions", () -> syncBondTransactions()); + try { Thread.sleep(800); } catch (InterruptedException ignored) {} submitNormalDbTask("首次-syncAllPlayerIps", () -> syncAllPlayerIps()); + try { Thread.sleep(800); } catch (InterruptedException ignored) {} submitNormalDbTask("首次-syncServiceProviders", () -> syncServiceProviders()); + try { Thread.sleep(800); } catch (InterruptedException ignored) {} submitNormalDbTask("首次-syncLandData", () -> syncLandData()); + try { Thread.sleep(800); } catch (InterruptedException ignored) {} submitNormalDbTask("首次-pollAdminChanges", () -> pollAdminChanges()); } }.runTaskLaterAsynchronously(plugin, 20L * 10); @@ -1177,14 +1187,21 @@ public class WebManager { if (hasRequest) { plugin.getLogger().info("[Web通信] 收到即时同步请求: " + players.toString()); - // 通过DB队列串行化执行同步 + // 通过DB队列串行化执行(每个任务间错开800ms) submitDbTask("即时-syncOnlinePlayers", () -> syncOnlinePlayers()); + try { Thread.sleep(800); } catch (InterruptedException ignored) {} submitDbTask("即时-pushWebLoginCredentials", () -> pushWebLoginCredentials()); + try { Thread.sleep(800); } catch (InterruptedException ignored) {} submitDbTask("即时-syncUserRegistrations", () -> syncUserRegistrations()); + try { Thread.sleep(800); } catch (InterruptedException ignored) {} submitNormalDbTask("即时-pullPendingTransactions", () -> pullPendingTransactions()); + try { Thread.sleep(800); } catch (InterruptedException ignored) {} submitNormalDbTask("即时-pullShopStock", () -> pullShopStock()); + try { Thread.sleep(800); } catch (InterruptedException ignored) {} submitNormalDbTask("即时-pullBondChanges", () -> pullBondChanges()); + try { Thread.sleep(800); } catch (InterruptedException ignored) {} submitNormalDbTask("即时-syncAllPlayerIps", () -> syncAllPlayerIps()); + try { Thread.sleep(800); } catch (InterruptedException ignored) {} submitNormalDbTask("即时-syncServiceProviders", () -> syncServiceProviders()); } } @@ -1205,13 +1222,19 @@ public class WebManager { syncAfterAllOffline = false; lastSyncDone = true; lastOnlineCheckTime = System.currentTimeMillis(); - // 通过DB队列串行化执行最后一轮同步 + // 通过DB队列串行化执行最后一轮同步(每个任务间错开800ms) submitDbTask("末轮-syncOnlinePlayers", () -> syncOnlinePlayers()); + try { Thread.sleep(800); } catch (InterruptedException ignored) {} submitDbTask("末轮-pushWebLoginCredentials", () -> pushWebLoginCredentials()); + try { Thread.sleep(800); } catch (InterruptedException ignored) {} submitDbTask("末轮-syncUserRegistrations", () -> syncUserRegistrations()); + try { Thread.sleep(800); } catch (InterruptedException ignored) {} submitDbTask("末轮-syncBondTransactions", () -> syncBondTransactions()); + try { Thread.sleep(800); } catch (InterruptedException ignored) {} submitNormalDbTask("末轮-pullPendingTransactions", () -> pullPendingTransactions()); + try { Thread.sleep(800); } catch (InterruptedException ignored) {} submitNormalDbTask("末轮-pullShopStock", () -> pullShopStock()); + try { Thread.sleep(800); } catch (InterruptedException ignored) {} submitNormalDbTask("末轮-pullBondChanges", () -> pullBondChanges()); plugin.getLogger().info("[Web通信] 检测到全员下线超60秒,执行最后一轮同步(通过DB队列),调度器继续运行(玩家上线自动恢复)"); plugin.getLogger().warning("\n" + @@ -1260,20 +1283,30 @@ public class WebManager { // ★ 玩家不在线时:只保留注册/登录轮询,其余任务全部跳过 boolean online = !Bukkit.getOnlinePlayers().isEmpty(); - // 登录/注册相关(始终执行) + // 登录/注册相关(始终执行,错开800ms避免瞬时堆叠) submitDbTask("周期-pushWebLoginCredentials", () -> pushWebLoginCredentials()); + try { Thread.sleep(800); } catch (InterruptedException ignored) {} submitDbTask("周期-syncUserRegistrations", () -> syncUserRegistrations()); + try { Thread.sleep(800); } catch (InterruptedException ignored) {} if (online) { - // 在线:执行全量同步 + // 在线:执行全量同步(每个任务错开800ms) submitDbTask("周期-syncOnlinePlayers", () -> syncOnlinePlayers()); + try { Thread.sleep(800); } catch (InterruptedException ignored) {} submitDbTask("周期-syncBondTransactions", () -> syncBondTransactions()); + try { Thread.sleep(800); } catch (InterruptedException ignored) {} submitNormalDbTask("周期-pullPendingTransactions", () -> pullPendingTransactions()); + try { Thread.sleep(800); } catch (InterruptedException ignored) {} submitNormalDbTask("周期-pullShopStock", () -> pullShopStock()); + try { Thread.sleep(800); } catch (InterruptedException ignored) {} submitNormalDbTask("周期-pullBondChanges", () -> pullBondChanges()); + try { Thread.sleep(800); } catch (InterruptedException ignored) {} submitNormalDbTask("周期-syncAllPlayerIps", () -> syncAllPlayerIps()); + try { Thread.sleep(800); } catch (InterruptedException ignored) {} submitNormalDbTask("周期-syncServiceProviders", () -> syncServiceProviders()); + try { Thread.sleep(800); } catch (InterruptedException ignored) {} submitNormalDbTask("周期-syncLandData", () -> syncLandData()); + try { Thread.sleep(800); } catch (InterruptedException ignored) {} submitNormalDbTask("周期-pollAdminChanges", () -> pollAdminChanges()); } else { // ★ 不在线:跳过非必要同步任务