#
Junjie
9 天以前 dc3f9cc91759823ce59486f19b138be4b296a0f1
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);