From d873278da9319c324418ef3377263fd3ab93b5f2 Mon Sep 17 00:00:00 2001 From: fengyarnom Date: Sat, 22 Feb 2025 09:44:40 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E6=81=A2=E5=A4=8D=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E5=92=8C=E6=B5=81=E9=87=8F=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E7=9A=84=E9=A2=91=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sideslope/task/SimStatusChecker.java | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/sec-beidou-rtcm/src/main/java/com/imdroid/sideslope/task/SimStatusChecker.java b/sec-beidou-rtcm/src/main/java/com/imdroid/sideslope/task/SimStatusChecker.java index 621618cf..e2158bde 100644 --- a/sec-beidou-rtcm/src/main/java/com/imdroid/sideslope/task/SimStatusChecker.java +++ b/sec-beidou-rtcm/src/main/java/com/imdroid/sideslope/task/SimStatusChecker.java @@ -1,6 +1,7 @@ package com.imdroid.sideslope.task; import com.alibaba.excel.util.StringUtils; +import com.imdroid.common.util.ThreadManager; import com.imdroid.secapi.dto.*; import com.imdroid.sideslope.sal.Device; import com.imdroid.sideslope.sal.DeviceService; @@ -47,40 +48,42 @@ public class SimStatusChecker { @Resource(name = "local") private DeviceService deviceService; - private static final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(3); - @Autowired private SimCardQueryServiceImpl simCardQueryServiceImpl; // 每小时执行一次状态检查调度 - //@Scheduled(cron = "0 0 * * * ?") - @Scheduled(cron = "0 */10 * * * ?") + @Scheduled(cron = "0 0 * * * ?") + //@Scheduled(cron = "0 */10 * * * ?") private void scheduleSimCardStatusCheck() { List onlineDevices = gnssStatusMapper.queryOnline(); logger.info("当前在线设备数量: {}", onlineDevices.size()); for (GnssStatusJoin onlineDevice : onlineDevices) { - //int delay = Math.abs(onlineDevice.getDeviceid().hashCode() % 3600 ); - int delay = Math.abs(onlineDevice.getDeviceid().hashCode() % 600 ); + int delay = Math.abs(onlineDevice.getDeviceid().hashCode() % 3600 ); logger.info("- 设备: {}, SIM状态查询,延迟执行: {}秒", onlineDevice.getDeviceid(), delay); - scheduler.schedule(() -> checkDeviceSimCardStatus(onlineDevice.getDeviceid()), - delay, TimeUnit.SECONDS); + ThreadManager.getScheduledThreadPool().schedule( + () -> checkDeviceSimCardStatus(onlineDevice.getDeviceid()), + delay, + TimeUnit.SECONDS + ); } } // 每两小时执行一次流量检查调度 - //@Scheduled(cron = "0 0 0/2 * * ?") - @Scheduled(cron = "0 */20 * * * ?") + @Scheduled(cron = "0 0 0/2 * * ?") private void scheduleSimCardTrafficCheck() { List onlineDevices = gnssStatusMapper.queryOnline(); logger.info("当前在线设备数量: {}", onlineDevices.size()); for (GnssStatusJoin onlineDevice : onlineDevices) { - int delay = Math.abs(onlineDevice.getDeviceid().hashCode() % 1200); + int delay = Math.abs(onlineDevice.getDeviceid().hashCode() % 7200); logger.debug("- 设备: {}, SIM流量查询,延迟执行: {}秒", onlineDevice.getDeviceid(), delay); - scheduler.schedule(() -> checkDeviceSimCardTraffic(onlineDevice.getDeviceid()), - delay, TimeUnit.SECONDS); + ThreadManager.getScheduledThreadPool().schedule( + () -> checkDeviceSimCardTraffic(onlineDevice.getDeviceid()), + delay, + TimeUnit.SECONDS + ); } }