From e8aed396752d24170221eed663820733a39b3c62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=AD=E5=BA=86=E6=B3=B0?= <12369755+htcloud1@user.noreply.gitee.com> Date: Wed, 16 Sep 2026 00:45:46 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BE=9B=E5=BA=94=E5=95=86=E8=B4=A6?= =?UTF-8?q?=E5=8F=B7=E6=8B=89=E5=8F=96=E5=90=AF=E5=8A=A8=E6=9C=9F=E5=A4=A7?= =?UTF-8?q?=E6=89=B9=E5=A4=B1=E8=B4=A5=20(=E5=90=AF=E5=8A=A8=E6=8E=A8?= =?UTF-8?q?=E8=BF=9F=2030s=20+=20=E5=90=8C=E6=AD=A5=E5=88=87=20100/?= =?UTF-8?q?=E6=89=B9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - @PostConstruct init() 加 Thread.sleep(30s), 避开启动期 Druid 首批物理连接未就绪导致全量失败 - sync() 改 100 条/批 + 批间 Thread.sleep(100ms), 让连接池稳定归还, 避免大批并发撑爆 Druid Co-Authored-By: Claude Code --- .../scheduler/SupplierAccountPullScheduler.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/ry-api/ruoyi-business/src/main/java/com/ruoyi/business/scheduler/SupplierAccountPullScheduler.java b/ry-api/ruoyi-business/src/main/java/com/ruoyi/business/scheduler/SupplierAccountPullScheduler.java index 1a54d01..b211d6e 100644 --- a/ry-api/ruoyi-business/src/main/java/com/ruoyi/business/scheduler/SupplierAccountPullScheduler.java +++ b/ry-api/ruoyi-business/src/main/java/com/ruoyi/business/scheduler/SupplierAccountPullScheduler.java @@ -68,13 +68,15 @@ public class SupplierAccountPullScheduler return t; }); - /** 启动后立即全量拉取 1 个月数据 (异步, 不阻塞 Spring 启动) */ + /** 启动后推迟 30s 全量拉取 1 个月数据 (异步, 不阻塞 Spring 启动; 推迟避开启动期 Druid 池首批连接未就绪) */ @PostConstruct public void init() { startupExecutor.submit(() -> { try { + // 启动期 Druid 首批物理连接未建好, 推迟 30s 让连接池就绪, 避免大批失败 + Thread.sleep(30_000); log.info("[SupplierAccountPull] 启动全量拉取开始 (近 {} 天)", fullPullDays()); pull(fullPullDays() * 24 * 60); } @@ -142,11 +144,21 @@ public class SupplierAccountPullScheduler fetched += size; // 同步到执行方 sys_user / biz_org / biz_person (按邮箱 upsert) + // 切批 100 条/批, 批间 sleep 100ms 让连接池归还, 避免大批并发撑爆 Druid if (size > 0) { List accounts = objectMapper.convertValue(rows, new TypeReference>() {}); - supplierAccountSyncService.sync(accounts); + final int BATCH = 100; + for (int i = 0; i < accounts.size(); i += BATCH) + { + List batch = accounts.subList(i, Math.min(i + BATCH, accounts.size())); + supplierAccountSyncService.sync(batch); + if (i + BATCH < accounts.size()) + { + Thread.sleep(100); + } + } } log.info("[SupplierAccountPull] page={} total={} 本页={} 同步完成", pageNum, total, size);