diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/opc/DeviceOpcProtocolRunable.java b/acs/nladmin-system/src/main/java/org/nl/acs/opc/DeviceOpcProtocolRunable.java index 073ec66..bd67886 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/opc/DeviceOpcProtocolRunable.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/opc/DeviceOpcProtocolRunable.java @@ -59,8 +59,9 @@ public class DeviceOpcProtocolRunable implements Runnable { @Override public void run() { while (true) { + Server server = null; try { - Server server = OpcServerUtl.getServerWithOutException(this.OpcServer.getOpc_host(), this.OpcServer.getCls_id(), this.OpcServer.getUser(), this.OpcServer.getPassword(), this.OpcServer.getDomain()); + server = OpcServerUtl.getServerWithOutException(this.OpcServer.getOpc_host(), this.OpcServer.getCls_id(), this.OpcServer.getUser(), this.OpcServer.getPassword(), this.OpcServer.getDomain()); Group group = server.addGroup(); List itemsString = new ArrayList(); Iterator it = this.protocols.iterator(); @@ -178,11 +179,29 @@ public class DeviceOpcProtocolRunable implements Runnable { } } } catch (Exception var30) { + if (!DeviceOpcSynchronizeAutoRun.isRun) { + System.out.println("opc线程停止2。。。"); + if (server != null) { + try { + server.disconnect(); + } catch (Exception var31) { + } + } + return; + } + String error_message = "设备信息同步异常"; if (!StrUtil.equals(this.message, error_message)) { log.warn("", var30); } + if (server != null) { + try { + server.disconnect(); + } catch (Exception e) { + } + } + try { Thread.sleep((long) (OpcConfig.synchronized_exception_wait_second * 1000)); } catch (InterruptedException e) { diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/opc/DeviceOpcSynchronizeAutoRun.java b/acs/nladmin-system/src/main/java/org/nl/acs/opc/DeviceOpcSynchronizeAutoRun.java index e6f01b8..0da5736 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/opc/DeviceOpcSynchronizeAutoRun.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/opc/DeviceOpcSynchronizeAutoRun.java @@ -23,6 +23,8 @@ public class DeviceOpcSynchronizeAutoRun extends AbstractAutoRunnable { @Autowired private OpcServerManageService opcServerManageService; + public static boolean isRun = false; + @Override public String getCode() { return DeviceOpcSynchronizeAutoRun.class.getSimpleName(); @@ -36,7 +38,7 @@ public class DeviceOpcSynchronizeAutoRun extends AbstractAutoRunnable { @Override public void autoRun() throws Exception { { - + isRun = true; Map servers = this.opcServerManageService.queryAllServerMap(); Map>> pros; do{ @@ -75,6 +77,7 @@ public class DeviceOpcSynchronizeAutoRun extends AbstractAutoRunnable { @Override public void after() { + isRun = false; this.executorService.shutdownNow(); this.executorService = Executors.newCachedThreadPool(); } diff --git a/acs/nladmin-system/src/main/resources/logback-spring.xml b/acs/nladmin-system/src/main/resources/logback-spring.xml index dd0b565..1781d46 100644 --- a/acs/nladmin-system/src/main/resources/logback-spring.xml +++ b/acs/nladmin-system/src/main/resources/logback-spring.xml @@ -175,6 +175,14 @@ https://juejin.cn/post/6844903775631572999 + + + + + + + +