优化: 全量同步任务间错开800ms执行,避免瞬间堆叠导致DB队列等待过久和HTTP 404
This commit is contained in:
@@ -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 {
|
||||
// ★ 不在线:跳过非必要同步任务
|
||||
|
||||
Reference in New Issue
Block a user