ty130316261 3 anni fa
parent
commit
f41724979c

+ 27 - 26
zd-modules/zd-netty/src/main/java/com/zd/netty/init/NettyStartListener.java

@@ -4,6 +4,7 @@ import com.zd.common.core.constant.HttpStatus;
 import com.zd.common.core.domain.R;
 import com.zd.common.core.enums.HardwareOperate;
 import com.zd.netty.service.IFridService;
+import com.zd.netty.thread.ThreadPoolTaskConfig;
 import com.zd.system.api.laboratory.RemoteLaboratoryService;
 import com.zd.system.api.laboratory.domain.RemoteLabHardware;
 import lombok.extern.slf4j.Slf4j;
@@ -29,39 +30,39 @@ public class NettyStartListener implements ApplicationRunner {
     @Resource
     private RemoteLaboratoryService laboratoryService;
     @Autowired
-    private  SocketServer socketServer;
+    private SocketServer socketServer;
+    @Resource
+    private ThreadPoolTaskConfig threadPoolTaskConfig;
 
     @Override
     public void run(ApplicationArguments args) {
         socketServer.start();
-        new Thread(new Runnable() {
-            @Override
-            public void run() {
-                synchronized (this){
-                    R<List<RemoteLabHardware>> listStart = laboratoryService.listStart();
-                    while (listStart.getCode() != HttpStatus.SUCCESS) {
-                        try {
-                            log.error("com.zd.system.api.laboratory.RemoteLaboratoryService:远程接口调用异常");
-                            //防止laboratory模块未启动完成,故每30秒执行一次程序,直到接口可以正常访问
-                            this.wait(30 * 1000L);
-                            NettyStartListener.this.run(args);
-                        } catch (InterruptedException e) {
-                            Thread.currentThread().interrupt();
-                        }
+
+        threadPoolTaskConfig.getAsyncExecutor().execute(() -> {
+            synchronized (this) {
+                R<List<RemoteLabHardware>> listStart = laboratoryService.listStart();
+                while (listStart.getCode() != HttpStatus.SUCCESS) {
+                    try {
+                        log.error("com.zd.system.api.laboratory.RemoteLaboratoryService:远程接口调用异常");
+                        //防止laboratory模块未启动完成,故每30秒执行一次程序,直到接口可以正常访问
+                        this.wait(30 * 1000L);
+                        NettyStartListener.this.run(args);
+                    } catch (InterruptedException e) {
+                        Thread.currentThread().interrupt();
                     }
-                    List<RemoteLabHardware> unitVos = listStart.getData();
-                    if (!unitVos.isEmpty()) {
-                        try {
-                            unitVos.stream()
-                                    .filter(u -> StringUtils.hasLength(u.getIpAddress()))
-                                    .filter(u -> u.getOperate() == HardwareOperate.OPEN)
-                                    .forEach(u -> fridService.start(u));
-                        } catch (Exception e) {
-                            e.fillInStackTrace();
-                        }
+                }
+                List<RemoteLabHardware> unitVos = listStart.getData();
+                if (!unitVos.isEmpty()) {
+                    try {
+                        unitVos.stream()
+                                .filter(u -> StringUtils.hasLength(u.getIpAddress()))
+                                .filter(u -> u.getOperate() == HardwareOperate.OPEN)
+                                .forEach(u -> fridService.start(u));
+                    } catch (Exception e) {
+                        e.fillInStackTrace();
                     }
                 }
             }
-        }).start();
+        });
     }
 }