From 9599a66cc56d6c13b0e960550c121aa5f06b6032 Mon Sep 17 00:00:00 2001 From: youpaishidifu Date: Thu, 25 Jun 2026 12:46:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=BC=BA:=20=E9=9A=8F=E6=9C=BA?= =?UTF-8?q?=E9=97=B4=E9=9A=94=E4=BB=8E=C2=B18=E7=A7=92=E6=89=A9=E5=A4=A7?= =?UTF-8?q?=E5=88=B0=C2=B110=E7=A7=92=EF=BC=9B=E4=BB=BB=E5=8A=A1=E9=97=B4?= =?UTF-8?q?=E9=9A=8F=E6=9C=BA=E5=BB=B6=E8=BF=9F=E4=BB=8E4-6=E7=A7=92?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=88=B06-8=E7=A7=92=EF=BC=9B=E5=87=8F?= =?UTF-8?q?=E5=B0=91PHP=E7=AB=AFSQLite=E9=94=81=E5=86=B2=E7=AA=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Sdf1_login/WebManager.java | 82 ++++++++++++------------ 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/src/main/java/Sdf1_login/WebManager.java b/src/main/java/Sdf1_login/WebManager.java index c149fbe..01e8661 100644 --- a/src/main/java/Sdf1_login/WebManager.java +++ b/src/main/java/Sdf1_login/WebManager.java @@ -801,24 +801,24 @@ public class WebManager { plugin.getLogger().info("[Web通信] 开始首次全量同步(通过DB队列串行化)..."); // 登录相关操作高优先级 submitDbTask("首次-syncUserRegistrations", () -> syncUserRegistrations()); - try { Thread.sleep(4000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {} + try { Thread.sleep(6000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {} submitDbTask("首次-pushWebLoginCredentials", () -> pushWebLoginCredentials()); - try { Thread.sleep(4000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {} + try { Thread.sleep(6000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {} // 普通同步操作低优先级(每个任务间随机间隔2-4秒,避免PHP端DB锁) submitNormalDbTask("首次-syncOnlinePlayers", () -> syncOnlinePlayers()); - try { Thread.sleep(4000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {} + try { Thread.sleep(6000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {} submitNormalDbTask("首次-syncShopData", () -> syncShopData()); - try { Thread.sleep(4000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {} + try { Thread.sleep(6000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {} submitNormalDbTask("首次-syncBondBalances", () -> syncBondBalances()); - try { Thread.sleep(4000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {} + try { Thread.sleep(6000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {} submitNormalDbTask("首次-syncBondTransactions", () -> syncBondTransactions()); - try { Thread.sleep(4000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {} + try { Thread.sleep(6000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {} submitNormalDbTask("首次-syncAllPlayerIps", () -> syncAllPlayerIps()); - try { Thread.sleep(4000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {} + try { Thread.sleep(6000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {} submitNormalDbTask("首次-syncServiceProviders", () -> syncServiceProviders()); - try { Thread.sleep(4000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {} + try { Thread.sleep(6000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {} submitNormalDbTask("首次-syncLandData", () -> syncLandData()); - try { Thread.sleep(4000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {} + try { Thread.sleep(6000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {} submitNormalDbTask("首次-pollAdminChanges", () -> pollAdminChanges()); } }.runTaskLaterAsynchronously(plugin, 20L * 10); @@ -1189,19 +1189,19 @@ public class WebManager { plugin.getLogger().info("[Web通信] 收到即时同步请求: " + players.toString()); // 通过DB队列串行化执行(每个任务间错开800ms) submitDbTask("即时-syncOnlinePlayers", () -> syncOnlinePlayers()); - try { Thread.sleep(4000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {} + try { Thread.sleep(6000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {} submitDbTask("即时-pushWebLoginCredentials", () -> pushWebLoginCredentials()); - try { Thread.sleep(4000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {} + try { Thread.sleep(6000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {} submitDbTask("即时-syncUserRegistrations", () -> syncUserRegistrations()); - try { Thread.sleep(4000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {} + try { Thread.sleep(6000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {} submitNormalDbTask("即时-pullPendingTransactions", () -> pullPendingTransactions()); - try { Thread.sleep(4000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {} + try { Thread.sleep(6000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {} submitNormalDbTask("即时-pullShopStock", () -> pullShopStock()); - try { Thread.sleep(4000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {} + try { Thread.sleep(6000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {} submitNormalDbTask("即时-pullBondChanges", () -> pullBondChanges()); - try { Thread.sleep(4000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {} + try { Thread.sleep(6000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {} submitNormalDbTask("即时-syncAllPlayerIps", () -> syncAllPlayerIps()); - try { Thread.sleep(4000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {} + try { Thread.sleep(6000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {} submitNormalDbTask("即时-syncServiceProviders", () -> syncServiceProviders()); } } @@ -1224,17 +1224,17 @@ public class WebManager { lastOnlineCheckTime = System.currentTimeMillis(); // 通过DB队列串行化执行最后一轮同步(每个任务间随机间隔2-4秒,避免与定时轮询冲突) submitDbTask("末轮-syncOnlinePlayers", () -> syncOnlinePlayers()); - try { Thread.sleep(4000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {} + try { Thread.sleep(6000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {} submitDbTask("末轮-pushWebLoginCredentials", () -> pushWebLoginCredentials()); - try { Thread.sleep(4000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {} + try { Thread.sleep(6000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {} submitDbTask("末轮-syncUserRegistrations", () -> syncUserRegistrations()); - try { Thread.sleep(4000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {} + try { Thread.sleep(6000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {} submitDbTask("末轮-syncBondTransactions", () -> syncBondTransactions()); - try { Thread.sleep(4000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {} + try { Thread.sleep(6000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {} submitNormalDbTask("末轮-pullPendingTransactions", () -> pullPendingTransactions()); - try { Thread.sleep(4000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {} + try { Thread.sleep(6000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {} submitNormalDbTask("末轮-pullShopStock", () -> pullShopStock()); - try { Thread.sleep(4000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {} + try { Thread.sleep(6000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {} submitNormalDbTask("末轮-pullBondChanges", () -> pullBondChanges()); plugin.getLogger().info("[Web通信] 检测到全员下线超60秒,执行最后一轮同步(通过DB队列),调度器继续运行(玩家上线自动恢复)"); plugin.getLogger().warning("\n" + @@ -1285,28 +1285,28 @@ public class WebManager { // 登录/注册相关(始终执行,随机间隔2-4秒避免PHP端DB锁) submitDbTask("周期-pushWebLoginCredentials", () -> pushWebLoginCredentials()); - try { Thread.sleep(4000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {} + try { Thread.sleep(6000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {} submitDbTask("周期-syncUserRegistrations", () -> syncUserRegistrations()); - try { Thread.sleep(4000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {} + try { Thread.sleep(6000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {} if (online) { // 在线:执行全量同步(每个任务随机间隔2-4秒) submitDbTask("周期-syncOnlinePlayers", () -> syncOnlinePlayers()); - try { Thread.sleep(4000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {} + try { Thread.sleep(6000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {} submitDbTask("周期-syncBondTransactions", () -> syncBondTransactions()); - try { Thread.sleep(4000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {} + try { Thread.sleep(6000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {} submitNormalDbTask("周期-pullPendingTransactions", () -> pullPendingTransactions()); - try { Thread.sleep(4000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {} + try { Thread.sleep(6000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {} submitNormalDbTask("周期-pullShopStock", () -> pullShopStock()); - try { Thread.sleep(4000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {} + try { Thread.sleep(6000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {} submitNormalDbTask("周期-pullBondChanges", () -> pullBondChanges()); - try { Thread.sleep(4000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {} + try { Thread.sleep(6000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {} submitNormalDbTask("周期-syncAllPlayerIps", () -> syncAllPlayerIps()); - try { Thread.sleep(4000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {} + try { Thread.sleep(6000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {} submitNormalDbTask("周期-syncServiceProviders", () -> syncServiceProviders()); - try { Thread.sleep(4000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {} + try { Thread.sleep(6000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {} submitNormalDbTask("周期-syncLandData", () -> syncLandData()); - try { Thread.sleep(4000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {} + try { Thread.sleep(6000 + (long)(Math.random() * 2000)); } catch (InterruptedException ignored) {} submitNormalDbTask("周期-pollAdminChanges", () -> pollAdminChanges()); } else { // ★ 不在线:跳过非必要同步任务 @@ -1321,7 +1321,7 @@ public class WebManager { checkSyncNotify(); } - }.runTaskTimerAsynchronously(plugin, 20L * randomIntervalSeconds(5), 20L * randomIntervalSeconds(5)); // activeSync 5±8秒 + }.runTaskTimerAsynchronously(plugin, 20L * randomIntervalSeconds(5), 20L * randomIntervalSeconds(5)); // activeSync 5±10秒 } /** @@ -1383,17 +1383,17 @@ public class WebManager { } } } - }.runTaskTimerAsynchronously(plugin, 20L * randomIntervalSeconds(5), 20L * randomIntervalSeconds(5)); // 交易轮询 5±8秒 + }.runTaskTimerAsynchronously(plugin, 20L * randomIntervalSeconds(5), 20L * randomIntervalSeconds(5)); // 交易轮询 5±10秒 } /** - * 生成定时器随机间隔(基础值 ±8秒) + * 生成定时器随机间隔(基础值 ±10秒) * 每个请求都是独立随机数,避开并发导致的SQL锁死 * @param baseSeconds 基础秒数 - * @return 随机秒数 [base-8, base+8],最小1秒 + * @return 随机秒数 [base-10, base+10],最小1秒 */ private long randomIntervalSeconds(long baseSeconds) { - long offset = (long) (Math.random() * 17) - 8; // -8 ~ +8 + long offset = (long) (Math.random() * 21) - 10; // -10 ~ +10 return Math.max(1, baseSeconds + offset); } @@ -1509,7 +1509,7 @@ public class WebManager { shopStockPollFailCount++; } } - }.runTaskTimerAsynchronously(plugin, 20L * randomIntervalSeconds(5), 20L * randomIntervalSeconds(5)); // 库存轮询 5±8秒 + }.runTaskTimerAsynchronously(plugin, 20L * randomIntervalSeconds(5), 20L * randomIntervalSeconds(5)); // 库存轮询 5±10秒 plugin.getLogger().info("[Web通信] 库存高频轮询已启动(每5秒)"); } @@ -1578,7 +1578,7 @@ public class WebManager { // 静默,避免刷屏 } } - }.runTaskTimerAsynchronously(plugin, 20L * randomIntervalSeconds(2), 20L * randomIntervalSeconds(2)); // CDK轮询 2±8秒(最小1秒) + }.runTaskTimerAsynchronously(plugin, 20L * randomIntervalSeconds(2), 20L * randomIntervalSeconds(2)); // CDK轮询 2±10秒(最小1秒) plugin.getLogger().info("[Web通信] CDK远程验证轮询已启动(每2秒)"); } @@ -1632,7 +1632,7 @@ public class WebManager { landSyncFailCount++; } } - }.runTaskTimerAsynchronously(plugin, 20L * randomIntervalSeconds(10), 20L * randomIntervalSeconds(10)); // 领地同步 10±8秒 + }.runTaskTimerAsynchronously(plugin, 20L * randomIntervalSeconds(10), 20L * randomIntervalSeconds(10)); // 领地同步 10±10秒 plugin.getLogger().info("[Web通信] 领地配置即时同步已启动(每10秒)"); } @@ -4796,7 +4796,7 @@ public class WebManager { } }); } - }.runTaskTimer(plugin, 20L * randomIntervalSeconds(3), 20L * randomIntervalSeconds(3)); // 注册轮询 3±8秒(最小1秒) + }.runTaskTimer(plugin, 20L * randomIntervalSeconds(3), 20L * randomIntervalSeconds(3)); // 注册轮询 3±10秒(最小1秒) } /**