From 728ad81fa10d2879654c5f9ae4314db94eafb865 Mon Sep 17 00:00:00 2001 From: Junjie <540245094@qq.com> Date: 星期五, 01 八月 2025 08:08:18 +0800 Subject: [PATCH] # --- src/main/java/com/zy/core/thread/impl/NyShuttleThread.java | 76 ++++++++++++++++++------------------- 1 files changed, 37 insertions(+), 39 deletions(-) diff --git a/src/main/java/com/zy/core/thread/impl/NyShuttleThread.java b/src/main/java/com/zy/core/thread/impl/NyShuttleThread.java index 19af9d7..312b527 100644 --- a/src/main/java/com/zy/core/thread/impl/NyShuttleThread.java +++ b/src/main/java/com/zy/core/thread/impl/NyShuttleThread.java @@ -52,6 +52,7 @@ private DeviceConfig deviceConfig; private RedisUtil redisUtil; private ShuttleProtocol shuttleProtocol; + private ShuttleAction shuttleAction = null; private static final boolean DEBUG = false;//璋冭瘯妯″紡 @@ -88,38 +89,35 @@ }); readThread.start(); -// //璁惧鎵ц -// Thread executeThread = new Thread(() -> { -// while (true) { -// try { -// ShuttleAction shuttleAction = null; -// try { -// shuttleAction = SpringUtils.getBean(ShuttleAction.class); -// }catch (Exception e){ -// continue; -// } -// -// if (shuttleAction == null) { -// continue; -// } -// -// Object object = redisUtil.get(RedisKeyType.SHUTTLE_FLAG.key + deviceConfig.getDeviceNo()); -// if (object == null) { -// continue; -// } -// -// Integer taskNo = Integer.valueOf(String.valueOf(object)); -// if (taskNo != 0) { -// //瀛樺湪浠诲姟闇�瑕佹墽琛� -// boolean result = shuttleAction.executeWork(deviceConfig.getDeviceNo(), taskNo); -// } -// Thread.sleep(100); -// } catch (Exception e) { -// e.printStackTrace(); -// } -// } -// }); -// executeThread.start(); + //璁惧鎵ц + Thread executeThread = new Thread(() -> { + while (true) { + try { + if (shuttleAction == null) { + try { + shuttleAction = SpringUtils.getBean(ShuttleAction.class); + }catch (Exception e){ + } + continue; + } + + Object object = redisUtil.get(RedisKeyType.SHUTTLE_FLAG.key + deviceConfig.getDeviceNo()); + if (object == null) { + continue; + } + + Integer taskNo = Integer.valueOf(String.valueOf(object)); + if (taskNo != 0) { + //瀛樺湪浠诲姟闇�瑕佹墽琛� + boolean result = shuttleAction.executeWork(deviceConfig.getDeviceNo(), taskNo); + } + Thread.sleep(100); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + executeThread.start(); } private void listenMessageFromRedis() { @@ -1214,16 +1212,16 @@ private JSONObject queryCommandStatus(String resultKey) { // 鑾峰彇鏈嶅姟鍣ㄥ搷搴� - // 灏濊瘯50娆� JSONObject result = null; - for (int i = 0; i < 50; i++) { + long startTime = System.currentTimeMillis(); + while (true) { + if((System.currentTimeMillis() - startTime) > 1000 * 10) { + break; + } + result = getRequestBody(resultKey); if (result == null) { - try { - Thread.sleep(500); - } catch (Exception e) { - e.printStackTrace(); - } + continue; }else { break; } -- Gitblit v1.9.1