From 470718b6f7de2688807a59b4e32f437624c51499 Mon Sep 17 00:00:00 2001
From: Junjie <DELL@qq.com>
Date: 星期四, 15 一月 2026 16:06:17 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/core/MainProcess.java |   41 +++++++++++++++++++++++++++--------------
 1 files changed, 27 insertions(+), 14 deletions(-)

diff --git a/src/main/java/com/zy/core/MainProcess.java b/src/main/java/com/zy/core/MainProcess.java
index d9e922c..dfac3b1 100644
--- a/src/main/java/com/zy/core/MainProcess.java
+++ b/src/main/java/com/zy/core/MainProcess.java
@@ -1,7 +1,6 @@
 package com.zy.core;
 
 import com.core.common.SpringUtils;
-import com.core.exception.CoolException;
 import com.zy.core.plugin.api.MainProcessPluginApi;
 import com.zy.core.properties.SystemProperties;
 import lombok.extern.slf4j.Slf4j;
@@ -20,38 +19,52 @@
     private String mainProcessPlugin;
     private MainProcessPluginApi mainProcessPluginApi;
     // 鎵�灞炵嚎绋�
-    private Thread thread;
+    private volatile Thread thread;
 
     /**
      * =====>>  寮�濮嬪伐浣�
      */
-    public void start(){
+    public void start() {
+        if (thread != null && thread.isAlive()) {
+            log.warn("MainProcess is already running.");
+            return;
+        }
+
         thread = new Thread(() -> {
             while (!Thread.currentThread().isInterrupted()) {
                 try {
+                    // 1. 鍔犺浇鎻掍欢
                     if (mainProcessPluginApi == null) {
-                        String className = mainProcessPlugin.contains(".") ? mainProcessPlugin : "com.zy.core.plugin." + mainProcessPlugin;
-                        Class<? extends MainProcessPluginApi> clazz = Class.forName(className).asSubclass(MainProcessPluginApi.class);
                         try {
+                            String className = mainProcessPlugin.contains(".") ? mainProcessPlugin : "com.zy.core.plugin." + mainProcessPlugin;
+                            Class<? extends MainProcessPluginApi> clazz = Class.forName(className).asSubclass(MainProcessPluginApi.class);
                             mainProcessPluginApi = SpringUtils.getBean(clazz);
-                        } catch (CoolException coolException) {
-                            continue;
+                        } catch (Exception e) {
+                            log.error("Failed to load mainProcessPlugin: {}", mainProcessPlugin, e);
                         }
                     }
 
-                    // 绯荤粺杩愯鐘舵�佸垽鏂�
-                    if (!SystemProperties.WCS_RUNNING_STATUS.get()) {
+                    // 濡傛灉鍔犺浇澶辫触锛岀瓑寰呭悗閲嶈瘯锛岄槻姝㈢┖鎸囬拡
+                    if (mainProcessPluginApi == null) {
+                        Thread.sleep(3000);
                         continue;
                     }
 
+                    // 2. 绯荤粺杩愯鐘舵�佸垽鏂�
+                    if (!SystemProperties.WCS_RUNNING_STATUS.get()) {
+                        // 闃叉蹇欑瓑 (Busy-wait optimization)
+                        Thread.sleep(1000);
+                        continue;
+                    }
+
+                    // 3. 鎵ц涓绘祦绋�
                     mainProcessPluginApi.run();
-                    // 闂撮殧
+
+                    // 4. 闂撮殧
                     Thread.sleep(200);
-                } catch (InterruptedException ie) {
-                    Thread.currentThread().interrupt();
-                    break;
+
                 } catch (Exception e) {
-                    e.printStackTrace();
+                    log.error("Error in MainProcess execution loop", e);
                 }
             }
         });

--
Gitblit v1.9.1