测试过程问题修改

This commit is contained in:
zgw
2026-01-06 20:09:20 +08:00
parent a490e7fba6
commit 4fef962e6c
15 changed files with 220 additions and 110 deletions

View File

@@ -89,6 +89,30 @@ public class ScheduleThread {
log.info("调度服务执行成功");
}
@PreDestroy
public void destroy() {
try {
for (String key : threadMap.keySet()) {
CustomThread<?> ct = threadMap.get(key);
if (ct != null && ct.getRunnable() != null) {
setRunnableIsRun(ct.getRunnable(), false);
}
}
for (String key : threadMap.keySet()) {
CustomThread<?> ct = threadMap.get(key);
if (ct != null && ct.getThread() != null) {
try {
ct.getThread().join(2000);
} catch (InterruptedException ignored) {
Thread.currentThread().interrupt();
}
}
}
} catch (Exception e) {
log.error("调度服务销毁时停止线程异常", e);
}
}
/**
* 调度初始化
*/
@@ -120,19 +144,19 @@ public class ScheduleThread {
for (DeviceSsj deviceSsj : deviceSsjs) {
ssjList.put(deviceSsj.getDeviceCode(), deviceSsj);
}
PlcSsjRead plcSsjRead = new PlcSsjRead(ssjList, new PlcConnectInfo("127.0.0.1", 1502));
PlcSsjRead plcSsjRead = new PlcSsjRead(ssjList, new PlcConnectInfo("192.168.10.100", 502));
Thread plcSsjReadThread = new Thread(plcSsjRead, "plcSsjReadCustomThread");
plcSsjReadCustomThread = new CustomThread<PlcSsjRead>(plcSsjReadThread, plcSsjRead);
//plc充电桩读取线程
ConcurrentHashMap<String, DeviceCdz> cdzList = new ConcurrentHashMap<>();
List<DeviceCdz> deviceCdzList = deviceCdzService.selectDeviceCdzList(new DeviceCdz());
for (DeviceCdz deviceCdz : deviceCdzList) {
cdzList.put(String.valueOf(deviceCdz.getId()), deviceCdz);
}
PlcCdzRead plcCdzRead = new PlcCdzRead(cdzList, new PlcConnectInfo("127.0.0.1", 1502));
Thread plcCdzReadThread = new Thread(plcCdzRead, "plcCdzjReadCustomThread");
plcCdzjReadCustomThread = new CustomThread<PlcCdzRead>(plcCdzReadThread, plcCdzRead);
// ConcurrentHashMap<String, DeviceCdz> cdzList = new ConcurrentHashMap<>();
// List<DeviceCdz> deviceCdzList = deviceCdzService.selectDeviceCdzList(new DeviceCdz());
// for (DeviceCdz deviceCdz : deviceCdzList) {
// cdzList.put(String.valueOf(deviceCdz.getId()), deviceCdz);
// }
// PlcCdzRead plcCdzRead = new PlcCdzRead(cdzList, new PlcConnectInfo("192.168.10.100", 502));
// Thread plcCdzReadThread = new Thread(plcCdzRead, "plcCdzjReadCustomThread");
// plcCdzjReadCustomThread = new CustomThread<PlcCdzRead>(plcCdzReadThread, plcCdzRead);
ConcurrentHashMap<String, DeviceTsj> tsjList = new ConcurrentHashMap<>();
@@ -142,14 +166,13 @@ public class ScheduleThread {
tsjList.put(t.getName(), t);
}
//plc提升机读取线程
PlcTsjRead plcTsjRead = new PlcTsjRead(tsjList, new PlcConnectInfo("127.0.0.1", 1502));
PlcTsjRead plcTsjRead = new PlcTsjRead(tsjList, new PlcConnectInfo("192.168.10.100", 502));
Thread plcTsjReadThread = new Thread(plcTsjRead, "plcTsjReadCustomThread");
plcTsjReadCustomThread = new CustomThread<PlcTsjRead>(plcTsjReadThread, plcTsjRead);
ConcurrentHashMap<String, DeviceSrgv> srgvList = new ConcurrentHashMap<>();
List<DeviceSrgv> srgvs = deviceSrgvService.selectDeviceSrgvList(new DeviceSrgv());
for (DeviceSrgv srgv : srgvs) {
srgvList.put(srgv.getDeviceId().toString(), srgv);
switch (srgv.getDeviceId()) {
case 1:
PlcSrgvRead plcSrgvRead1 = new PlcSrgvRead(srgv, new PlcConnectInfo(srgv.getIp(), srgv.getPort()));
@@ -162,6 +185,7 @@ public class ScheduleThread {
plcSrgvReadCustomThread2 = new CustomThread<PlcSrgvRead>(plcSrgvReadThread2, plcSrgvRead2);
break;
}
srgvList.put(srgv.getDeviceId().toString(), srgv);
}
PlcSrgvRead.deviceSrgvMap = srgvList;
//监控线程
@@ -173,7 +197,7 @@ public class ScheduleThread {
public void refreshThreadMap() {
registerThread("plcSsjReadCustomThread", plcSsjReadCustomThread, "PLC输送机读取线程", "read");
registerThread("plcCdzjReadCustomThread", plcCdzjReadCustomThread, "PLC充电桩读取线程", "read");
// registerThread("plcCdzjReadCustomThread", plcCdzjReadCustomThread, "PLC充电桩读取线程", "read");
registerThread("plcTsjReadCustomThread", plcTsjReadCustomThread, "PLC提升机读取线程", "read");
registerThread("plcSrgvReadCustomThread1", plcSrgvReadCustomThread1, "PLC四向车1读取线程", "read");
registerThread("plcSrgvReadCustomThread2", plcSrgvReadCustomThread2, "PLC四向车2读取线程", "read");
@@ -202,7 +226,7 @@ public class ScheduleThread {
plcTsjReadCustomThread.getThread().start();
monitoringCustomThread.getThread().start();
//充电桩读取线程
plcCdzjReadCustomThread.getThread().start();
// plcCdzjReadCustomThread.getThread().start();
isRun = true;
}