Browse Source

OPC线程同步修改

master
管理员 2 years ago
parent
commit
7fca8d0795
  1. 21
      acs/nladmin-system/src/main/java/org/nl/acs/opc/DeviceOpcProtocolRunable.java
  2. 5
      acs/nladmin-system/src/main/java/org/nl/acs/opc/DeviceOpcSynchronizeAutoRun.java
  3. 8
      acs/nladmin-system/src/main/resources/logback-spring.xml

21
acs/nladmin-system/src/main/java/org/nl/acs/opc/DeviceOpcProtocolRunable.java

@ -59,8 +59,9 @@ public class DeviceOpcProtocolRunable implements Runnable {
@Override @Override
public void run() { public void run() {
while (true) { while (true) {
Server server = null;
try { 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(); Group group = server.addGroup();
List<String> itemsString = new ArrayList(); List<String> itemsString = new ArrayList();
Iterator it = this.protocols.iterator(); Iterator it = this.protocols.iterator();
@ -178,11 +179,29 @@ public class DeviceOpcProtocolRunable implements Runnable {
} }
} }
} catch (Exception var30) { } catch (Exception var30) {
if (!DeviceOpcSynchronizeAutoRun.isRun) {
System.out.println("opc线程停止2。。。");
if (server != null) {
try {
server.disconnect();
} catch (Exception var31) {
}
}
return;
}
String error_message = "设备信息同步异常"; String error_message = "设备信息同步异常";
if (!StrUtil.equals(this.message, error_message)) { if (!StrUtil.equals(this.message, error_message)) {
log.warn("", var30); log.warn("", var30);
} }
if (server != null) {
try {
server.disconnect();
} catch (Exception e) {
}
}
try { try {
Thread.sleep((long) (OpcConfig.synchronized_exception_wait_second * 1000)); Thread.sleep((long) (OpcConfig.synchronized_exception_wait_second * 1000));
} catch (InterruptedException e) { } catch (InterruptedException e) {

5
acs/nladmin-system/src/main/java/org/nl/acs/opc/DeviceOpcSynchronizeAutoRun.java

@ -23,6 +23,8 @@ public class DeviceOpcSynchronizeAutoRun extends AbstractAutoRunnable {
@Autowired @Autowired
private OpcServerManageService opcServerManageService; private OpcServerManageService opcServerManageService;
public static boolean isRun = false;
@Override @Override
public String getCode() { public String getCode() {
return DeviceOpcSynchronizeAutoRun.class.getSimpleName(); return DeviceOpcSynchronizeAutoRun.class.getSimpleName();
@ -36,7 +38,7 @@ public class DeviceOpcSynchronizeAutoRun extends AbstractAutoRunnable {
@Override @Override
public void autoRun() throws Exception { public void autoRun() throws Exception {
{ {
isRun = true;
Map<String, OpcServerManageDto> servers = this.opcServerManageService.queryAllServerMap(); Map<String, OpcServerManageDto> servers = this.opcServerManageService.queryAllServerMap();
Map<String, List<List<OpcItemDto>>> pros; Map<String, List<List<OpcItemDto>>> pros;
do{ do{
@ -75,6 +77,7 @@ public class DeviceOpcSynchronizeAutoRun extends AbstractAutoRunnable {
@Override @Override
public void after() { public void after() {
isRun = false;
this.executorService.shutdownNow(); this.executorService.shutdownNow();
this.executorService = Executors.newCachedThreadPool(); this.executorService = Executors.newCachedThreadPool();
} }

8
acs/nladmin-system/src/main/resources/logback-spring.xml

@ -175,6 +175,14 @@ https://juejin.cn/post/6844903775631572999
<appender-ref ref="asyncFileAppender"/> <appender-ref ref="asyncFileAppender"/>
<appender-ref ref="lokiAppender"/> <appender-ref ref="lokiAppender"/>
</logger> </logger>
<logger name="org.jinterop" level="ERROR" additivity="false">
<appender-ref ref="asyncFileAppender"/>
<appender-ref ref="lokiAppender"/>
</logger>
<logger name="org.openscada" level="ERROR" additivity="false">
<appender-ref ref="asyncFileAppender"/>
<appender-ref ref="lokiAppender"/>
</logger>
</springProfile> </springProfile>

Loading…
Cancel
Save