From aa151079c2d02047f6cb5f8ad56ff92b98544e99 Mon Sep 17 00:00:00 2001
From: Junjie <DELL@qq.com>
Date: 星期三, 14 一月 2026 08:30:49 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/core/MainProcess.java | 47 +++++++++++++++++++++++++++++++++++------------
1 files changed, 35 insertions(+), 12 deletions(-)
diff --git a/src/main/java/com/zy/core/MainProcess.java b/src/main/java/com/zy/core/MainProcess.java
index 4b36c14..70f7954 100644
--- a/src/main/java/com/zy/core/MainProcess.java
+++ b/src/main/java/com/zy/core/MainProcess.java
@@ -1,8 +1,7 @@
package com.zy.core;
import com.core.common.SpringUtils;
-import com.core.exception.CoolException;
-import com.zy.core.plugin.MainProcessPluginApi;
+import com.zy.core.plugin.api.MainProcessPluginApi;
import com.zy.core.properties.SystemProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
@@ -20,38 +19,62 @@
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) {
+ log.info("MainProcess thread interrupted, stopping...");
Thread.currentThread().interrupt();
break;
} catch (Exception e) {
- e.printStackTrace();
+ log.error("Error in MainProcess execution loop", e);
+ try {
+ // 閬垮厤寮傚父瀵艰嚧鐨勭媯鍒锋棩蹇�
+ Thread.sleep(1000);
+ } catch (InterruptedException ex) {
+ Thread.currentThread().interrupt();
+ }
}
}
});
--
Gitblit v1.9.1