123
zhang
9 天以前 0a37b816117828dfc216d00c17724900f4bb14e3
zy-asc-conveyor/src/main/java/com/zy/acs/conveyor/core/operation/ConveyorBackgroundService.java
@@ -31,12 +31,11 @@
    private ScheduledExecutorService executorService;
    private final AtomicBoolean running = new AtomicBoolean(false);
    private long lastDbUpdateTime = 0;
    private static final int LOG_INTERVAL_MS = 30000;
    private static final int LOG_INTERVAL_MS = 300000;
    @PostConstruct
    public void init() {
@@ -44,23 +43,22 @@
        executorService = Executors.newSingleThreadScheduledExecutor(r -> {
            Thread thread = new Thread(r);
            thread.setName("cv-background-thread");
            thread.setDaemon(true);
            //thread.setDaemon(true);
            return thread;
        });
        // 启动定时任务
        executorService.scheduleAtFixedRate(this::processConveyorTasks,
        executorService.scheduleWithFixedDelay(this::processConveyorTasks,
                properties.getInitialDelay(),
                properties.getInterval(),
                TimeUnit.MILLISECONDS);
        running.set(true);
        log.info("输送线后台服务线程初始化完成");
        News.info("输送线后台服务线程初始化完成");
    }
    private void processConveyorTasks() {
        // 系统运行状态判断
        if (!SystemProperties.WCS_RUNNING_STATUS.get() || !running.get()) {
            log.debug("系统未运行或服务已停止,跳过输送线任务处理");
        if (!SystemProperties.WCS_RUNNING_STATUS.get()) {
            News.info("系统未运行或服务已停止,跳过输送线任务处理");
            return;
        }
        long currentTime = System.currentTimeMillis();
@@ -68,21 +66,23 @@
            News.info("执行输送线操作");
            lastDbUpdateTime = currentTime;
        }
        try {
            // 执行配置的操作序列
            for (CtuOperationConfig config : properties.getOperations()) {
        // 执行配置的操作序列
        for (CtuOperationConfig config : properties.getOperations()) {
            try {
                operationExecutor.execute(config);
            } catch (Exception e) {
                News.error("输送线操作执行最终失败, type={}, error={}", config.getType(), e.getMessage());
                // 可选:发送告警、暂停调度等
            }
        } catch (Exception e) {
            log.error("输送线任务处理异常", e);
        }
    }
    @PreDestroy
    public void shutDown() {
        running.set(false);
        if (executorService != null && !executorService.isShutdown()) {
            log.info("正在关闭输送线后台服务线程...");
            News.info("正在关闭输送线后台服务线程...");
            executorService.shutdown();
            try {
                if (!executorService.awaitTermination(5, TimeUnit.SECONDS)) {
@@ -92,7 +92,7 @@
                executorService.shutdownNow();
                Thread.currentThread().interrupt();
            }
            log.info("输送线后台服务线程已关闭");
            News.info("输送线后台服务线程已关闭");
        }
    }
}