修改modbus读取设备数据连接池配置
This commit is contained in:
@ -31,6 +31,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
@ -81,7 +82,6 @@ public class ModbusPoller {
|
||||
this.scheduledTask = scheduledTask;
|
||||
}
|
||||
|
||||
|
||||
public void pollAllDevices() {
|
||||
Path devicesDir = Paths.get(System.getProperty("user.dir"), "devices");
|
||||
if (!Files.exists(devicesDir)) {
|
||||
@ -120,17 +120,24 @@ public class ModbusPoller {
|
||||
for (Map.Entry<String, List<DeviceConfig>> entry : groupedConfigs.entrySet()) {
|
||||
String groupKey = entry.getKey();
|
||||
List<DeviceConfig> configs = entry.getValue();
|
||||
// 取其中一个配置的时间间隔作为该组任务的执行周期
|
||||
// long interval = configs.get(0).getTime();
|
||||
scheduledTask.startTask(groupKey, () -> {
|
||||
for (DeviceConfig config : configs) {
|
||||
try {
|
||||
scheduledStart(config);
|
||||
} catch (Exception e) {
|
||||
log.error("采集设备数据异常: {}", config.getDeviceName(), e);
|
||||
}
|
||||
}
|
||||
}, interval);
|
||||
try {
|
||||
CompletableFuture.runAsync(() -> {
|
||||
for (DeviceConfig config : configs) {
|
||||
try {
|
||||
scheduledStart(config);
|
||||
} catch (Exception e) {
|
||||
log.error("采集设备数据异常: {}", config.getDeviceName(), e);
|
||||
}
|
||||
}
|
||||
})
|
||||
.exceptionally(e -> {
|
||||
log.error("采集设备数据{}轮询异常", groupKey, e);
|
||||
return null;
|
||||
})
|
||||
.thenRun(() -> log.info("采集设备数据{}轮询任务执行完成", groupKey));
|
||||
} catch (Exception e) {
|
||||
log.error("采集设备数据{}任务失败", groupKey, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user