From dc3f9cc91759823ce59486f19b138be4b296a0f1 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期二, 28 四月 2026 09:43:28 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/core/move/StationMoveCoordinator.java |   21 ++++++++++++++++++---
 1 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/src/main/java/com/zy/core/move/StationMoveCoordinator.java b/src/main/java/com/zy/core/move/StationMoveCoordinator.java
index 075ea36..2f167e1 100644
--- a/src/main/java/com/zy/core/move/StationMoveCoordinator.java
+++ b/src/main/java/com/zy/core/move/StationMoveCoordinator.java
@@ -26,6 +26,8 @@
 public class StationMoveCoordinator {
 
     private static final int SESSION_EXPIRE_SECONDS = 60 * 60 * 24;
+    private static final long TASK_DISPATCH_LOCK_SLOW_THRESHOLD_MS = 50L;
+    private static final long RECORD_DISPATCH_SLOW_THRESHOLD_MS = 50L;
     private final Map<Integer, ReentrantLock> taskDispatchLocks = new ConcurrentHashMap<>();
 
     @Autowired
@@ -94,12 +96,18 @@
         if (taskNo == null || taskNo <= 0) {
             return supplier.get();
         }
-        // 鍚屼竴浠诲姟鐨勫垏璺拰鍒嗘鍙戦�佸繀椤诲叡浜竴鎶婇攣锛岄伩鍏嶆棫 routeVersion 鍦ㄧ嚎绋嬫櫄鍒版椂缁х画鎶婁笂涓�鏉℃鍛戒护鍐欏嚭鍘汇��
         ReentrantLock lock = taskDispatchLocks.computeIfAbsent(taskNo, key -> new ReentrantLock());
+        long waitStartMs = System.currentTimeMillis();
         lock.lock();
+        long lockWaitMs = System.currentTimeMillis() - waitStartMs;
+        long holdStartMs = System.currentTimeMillis();
         try {
             return supplier.get();
         } finally {
+            long holdMs = System.currentTimeMillis() - holdStartMs;
+            if (lockWaitMs > TASK_DISPATCH_LOCK_SLOW_THRESHOLD_MS || holdMs > TASK_DISPATCH_LOCK_SLOW_THRESHOLD_MS) {
+                log.warn("taskDispatchLock slow, taskNo={}, lockWaitMs={}ms, lockHoldMs={}ms", taskNo, lockWaitMs, holdMs);
+            }
             lock.unlock();
         }
     }
@@ -138,6 +146,7 @@
             return null;
         }
 
+        long startMs = System.currentTimeMillis();
         StationMoveSession current = loadSession(taskNo);
         long now = System.currentTimeMillis();
         String pathSignature = buildPathSignature(command);
@@ -177,10 +186,16 @@
 
         command.setRouteVersion(session.getRouteVersion());
         saveSession(session);
-        log.info("recordDispatch done, taskNo={}, routeVersion={}, reuse={}, prevRouteVersion={}, dispatchStationId={}, triggerName={}",
+        long recordDispatchCostMs = System.currentTimeMillis() - startMs;
+        log.info("recordDispatch done, taskNo={}, routeVersion={}, reuse={}, prevRouteVersion={}, dispatchStationId={}, triggerName={}, recordDispatchCostMs={}ms",
                 taskNo, session.getRouteVersion(), reuseCurrent,
                 current == null ? null : current.getRouteVersion(),
-                dispatchStationId, triggerName);
+                dispatchStationId, triggerName, recordDispatchCostMs);
+        if (recordDispatchCostMs > RECORD_DISPATCH_SLOW_THRESHOLD_MS) {
+            log.warn("recordDispatch slow, taskNo={}, dispatchStationId={}, triggerName={}, recordDispatchCostMs={}ms, pathSize={}",
+                    taskNo, dispatchStationId, triggerName, recordDispatchCostMs,
+                    fullPathStationIds == null ? 0 : fullPathStationIds.size());
+        }
 
         if (circleRoute) {
             saveLegacyCircleCommand(taskNo, command);

--
Gitblit v1.9.1