From 7fca8d0795a7d68d4fa5cb744c5408af6c1a2e52 Mon Sep 17 00:00:00 2001 From: ludj Date: Fri, 6 Jan 2023 11:02:04 +0800 Subject: [PATCH] =?UTF-8?q?OPC=E7=BA=BF=E7=A8=8B=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nl/acs/opc/DeviceOpcProtocolRunable.java | 21 ++++++++++++++++++- .../acs/opc/DeviceOpcSynchronizeAutoRun.java | 5 ++++- .../src/main/resources/logback-spring.xml | 8 +++++++ 3 files changed, 32 insertions(+), 2 deletions(-) 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 + + + + + + + +