From 8ca9bebfd1c8cdac3f64842df1d7c640ce68fa1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=89=E6=B5=A9=E6=B5=A9?= <1036606149@qq.com> Date: Mon, 30 Dec 2024 09:33:56 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E3=80=91IoT:=20=E6=9B=B4=E6=96=B0=20HttpPlugin=EF=BC=8C?= =?UTF-8?q?=E9=87=8D=E6=9E=84=E7=BA=BF=E7=A8=8B=E6=B1=A0=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96=E9=80=BB=E8=BE=91=E4=BB=A5=E7=A1=AE=E4=BF=9D=E7=BA=BF?= =?UTF-8?q?=E7=A8=8B=E6=B1=A0=E6=B4=BB=E8=B7=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iocoder/yudao/module/iot/plugin/HttpPlugin.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/yudao-module-iot/yudao-module-iot-plugin/yudao-module-iot-http-plugin/src/main/java/cn/iocoder/yudao/module/iot/plugin/HttpPlugin.java b/yudao-module-iot/yudao-module-iot-plugin/yudao-module-iot-http-plugin/src/main/java/cn/iocoder/yudao/module/iot/plugin/HttpPlugin.java index 70da0131ce..66e0c69a39 100644 --- a/yudao-module-iot/yudao-module-iot-plugin/yudao-module-iot-http-plugin/src/main/java/cn/iocoder/yudao/module/iot/plugin/HttpPlugin.java +++ b/yudao-module-iot/yudao-module-iot-plugin/yudao-module-iot-http-plugin/src/main/java/cn/iocoder/yudao/module/iot/plugin/HttpPlugin.java @@ -19,12 +19,12 @@ public class HttpPlugin extends Plugin { private static final int PORT = 8092; - private final ExecutorService executorService; + private ExecutorService executorService; private DeviceDataApi deviceDataApi; public HttpPlugin(PluginWrapper wrapper) { super(wrapper); - // 创建单线程池 + // 初始化线程池 this.executorService = Executors.newSingleThreadExecutor(); } @@ -32,6 +32,11 @@ public class HttpPlugin extends Plugin { public void start() { log.info("HttpPlugin.start()"); + // 重新初始化线程池,确保它是活跃的 + if (executorService.isShutdown() || executorService.isTerminated()) { + executorService = Executors.newSingleThreadExecutor(); + } + // 从 ServiceRegistry 中获取主程序暴露的 DeviceDataApi 接口实例 deviceDataApi = ServiceRegistry.getService(DeviceDataApi.class); if (deviceDataApi == null) { @@ -79,11 +84,11 @@ public class HttpPlugin extends Plugin { future.channel().closeFuture().sync(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); - log.error("HTTP 服务启动中断", e); + log.warn("HTTP 服务启动被中断", e); } finally { bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } } -} +} \ No newline at end of file