Browse Source

#定时刷新数据任务运行堵塞邮件发送

zhongwei
yang_shj 7 months ago
parent
commit
d3a9d08b94
  1. 62
      hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/monitor/impl/MonitorServiceImpl.java

62
hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/monitor/impl/MonitorServiceImpl.java

@ -85,8 +85,9 @@ public class MonitorServiceImpl implements MonitorService {
private final IAnalyseDataSearchClient analyseDataSearchClient; private final IAnalyseDataSearchClient analyseDataSearchClient;
private static final ExecutorService pool = new ThreadPoolExecutor(10, 10, 60L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(256), new ThreadFactoryBuilder().setNameFormat("load-monitoring-pool-%d").build(), new ThreadPoolExecutor.CallerRunsPolicy()); private static final ExecutorService pool = new ThreadPoolExecutor(20, 20, 2L, TimeUnit.MINUTES, new LinkedBlockingQueue<>(256), new ThreadFactoryBuilder().setNameFormat("load-monitoring-pool-%d").build(), new ThreadPoolExecutor.CallerRunsPolicy());
private static boolean isSendMail = true;
@Value("${hzims.equipment.emInfo.emInfoList}") @Value("${hzims.equipment.emInfo.emInfoList}")
public String device_cache_final; public String device_cache_final;
@ -232,18 +233,19 @@ public class MonitorServiceImpl implements MonitorService {
try { try {
// 等待所有线程执行完成(至多等待三秒,超过三秒任务认为线程发生阻塞) // 等待所有线程执行完成(至多等待三秒,超过三秒任务认为线程发生阻塞)
boolean flag = countDownLatch.await(3,TimeUnit.SECONDS); boolean flag = countDownLatch.await(3,TimeUnit.SECONDS);
if(!flag){ if(!flag && isSendMail){
log.error("实时数据调度发生阻塞 : {}" , DateUtil.format(new Date(),DateUtil.PATTERN_DATETIME)); log.error("实时数据调度发生阻塞 : {}" , DateUtil.format(new Date(),DateUtil.PATTERN_DATETIME));
isSendMail = false;
// 发生邮件 // 发生邮件
this.sendMonthReport("实时数据运行堵塞"); this.sendMonthReport("实时数据运行堵塞");
}else if(flag){
// redis 存储
redisTemplate.opsForValue().set(real_cache_final,JSONObject.toJSONString(valueMap));
redisTemplate.opsForValue().set(real_gather_cache_final,JSONObject.toJSONString(keyMap));
} }
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace();
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
} }
// redis 存储
redisTemplate.opsForValue().set(real_cache_final,JSONObject.toJSONString(valueMap));
redisTemplate.opsForValue().set(real_gather_cache_final,JSONObject.toJSONString(keyMap));
} }
/** /**
@ -310,44 +312,40 @@ public class MonitorServiceImpl implements MonitorService {
// 切割数据遍历 // 切割数据遍历
for(Map<String, List<StationAttributeEntity>> item : limit){ for(Map<String, List<StationAttributeEntity>> item : limit){
// 提交线程任务 // 提交线程任务
pool.submit(()->{ pool.execute(()->{
try{ item.forEach((key,value)->{
item.forEach((key,value)->{ RealStationVo realStation = new RealStationVo();
RealStationVo realStation = new RealStationVo(); // 设备信息
// 设备信息 List<RealDeviceVo> devices = this.monitorRealDevice(value,realTimeData);
List<RealDeviceVo> devices = this.monitorRealDevice(value,realTimeData); // 设备状态
// 设备状态 this.deviceStatus(devices,deviceClassifyMap);
this.deviceStatus(devices,deviceClassifyMap); realStation.setDeviceList(devices.stream().sorted(Comparator.comparing(RealDeviceVo::getDeviceName)).collect(Collectors.toList()));
realStation.setDeviceList(devices.stream().sorted(Comparator.comparing(RealDeviceVo::getDeviceName)).collect(Collectors.toList())); // 站点基础信息: 编码、名称、限制水位、服务类型、机构、排序
// 站点基础信息: 编码、名称、限制水位、服务类型、机构、排序 this.stationBaseInfo(stations.stream().filter(station->key.equals(station.getCode())).findFirst(),sorts,realStation);
this.stationBaseInfo(stations.stream().filter(station->key.equals(station.getCode())).findFirst(),sorts,realStation); // 站点总功率计算
// 站点总功率计算 this.stationActivePower(devices,realStation);
this.stationActivePower(devices,realStation); // 站点铃铛、数据中断状态
// 站点铃铛、数据中断状态 this.stationStatus(aborts,bells,realStation);
this.stationStatus(aborts,bells,realStation); realStations.add(realStation);
realStations.add(realStation); });
}); countDownLatch.countDown();
countDownLatch.countDown();
}catch (Exception e){
countDownLatch.countDown();
Thread.currentThread().interrupt();
}
}); });
} }
// 等待所有线程执行完成 // 等待所有线程执行完成
try { try {
// 等待所有线程执行完成(至多等待二秒,超过二秒任务认为线程发生阻塞) // 等待所有线程执行完成(至多等待二秒,超过二秒任务认为线程发生阻塞)
boolean flag = countDownLatch.await(2,TimeUnit.SECONDS); boolean flag = countDownLatch.await(3,TimeUnit.SECONDS);
if(!flag){ if(!flag && isSendMail){
log.error("集中监控数据调度发生阻塞 : {}" , DateUtil.format(new Date(),DateUtil.PATTERN_DATETIME)); log.error("集中监控数据调度发生阻塞 : {}" , DateUtil.format(new Date(),DateUtil.PATTERN_DATETIME));
isSendMail = false;
// 发生邮件 // 发生邮件
this.sendMonthReport("集中监控数据运行堵塞"); this.sendMonthReport("集中监控数据运行堵塞");
}else if(flag){
redisTemplate.opsForValue().set(moniter_station_cache_final, realStations);
} }
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace();
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
} }
redisTemplate.opsForValue().set(moniter_station_cache_final, realStations);
} }
/** /**

Loading…
Cancel
Save