From c3b04f92b4c196644a80a912a601b5c29194f71b Mon Sep 17 00:00:00 2001
From: ‘liusuyi’ <1951119284@qq.com>
Date: 星期六, 05 八月 2023 09:37:52 +0800
Subject: [PATCH] 增加线程池配置信息 修改雷达数据最近一次引导从redis获取
---
ard-work/src/main/java/com/ruoyi/alarm/config/AsyncConfiguration.java | 42 ++++++++-------------
ruoyi-admin/src/main/java/com/ruoyi/RuoYiApplication.java | 2
ard-work/src/main/java/com/ruoyi/alarm/global/service/impl/GlobalAlarmServiceImpl.java | 21 ++++++----
ard-work/src/main/java/com/ruoyi/test/ReadAccessDatabase.java | 21 +++++-----
ruoyi-admin/src/main/resources/application-ard.yml | 11 ++++-
5 files changed, 50 insertions(+), 47 deletions(-)
diff --git a/ard-work/src/main/java/com/ruoyi/alarm/config/AsyncConfiguration.java b/ard-work/src/main/java/com/ruoyi/alarm/config/AsyncConfiguration.java
index 4052c82..f3b8be4 100644
--- a/ard-work/src/main/java/com/ruoyi/alarm/config/AsyncConfiguration.java
+++ b/ard-work/src/main/java/com/ruoyi/alarm/config/AsyncConfiguration.java
@@ -1,11 +1,14 @@
package com.ruoyi.alarm.config;
+import com.google.errorprone.annotations.Var;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import java.util.concurrent.Executor;
+import java.util.concurrent.ThreadPoolExecutor;
/**
* @ClassName: AsyncConfiguration
@@ -17,44 +20,31 @@
@Configuration
@EnableAsync(proxyTargetClass = true)
public class AsyncConfiguration {
- @Bean("loginExecutor")
- public Executor executor(){
- ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
- //閰嶇疆鏍稿績绾跨▼鏁�
- executor.setCorePoolSize(15);
- //閰嶇疆鏈�澶х嚎绋嬫暟
- executor.setMaxPoolSize(30);
- //閰嶇疆闃熷垪澶у皬
- executor.setQueueCapacity(1000);
- //绾跨▼鐨勫悕绉板墠缂�
- executor.setThreadNamePrefix("loginExecutor-");
- //绾跨▼娲昏穬鏃堕棿锛堢锛�
- //executor.setKeepAliveSeconds(60);
- //绛夊緟鎵�鏈変换鍔$粨鏉熷悗鍐嶅叧闂嚎绋嬫睜
- executor.setWaitForTasksToCompleteOnShutdown(true);
- //璁剧疆鎷掔粷绛栫暐
- //executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
- //鎵ц鍒濆鍖�
- executor.initialize();
- return executor;
- }
+ @Value("${ThreadPoolTask.corePoolSize}")
+ Integer corePoolSize;
+ @Value("${ThreadPoolTask.maxPoolSize}")
+ Integer maxPoolSize;
+ @Value("${ThreadPoolTask.keepAliveSeconds}")
+ Integer keepAliveSeconds;
+ @Value("${ThreadPoolTask.queueCapacity}")
+ Integer queueCapacity;
@Bean("alarmExecutor")
public Executor alarmExecutor(){
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
//閰嶇疆鏍稿績绾跨▼鏁�
- executor.setCorePoolSize(15);
+ executor.setCorePoolSize(corePoolSize);
//閰嶇疆鏈�澶х嚎绋嬫暟
- executor.setMaxPoolSize(30);
+ executor.setMaxPoolSize(maxPoolSize);
//閰嶇疆闃熷垪澶у皬
- executor.setQueueCapacity(1000);
+ executor.setQueueCapacity(queueCapacity);
//绾跨▼鐨勫悕绉板墠缂�
executor.setThreadNamePrefix("alarmExecutor-");
//绾跨▼娲昏穬鏃堕棿锛堢锛�
- //executor.setKeepAliveSeconds(60);
+ executor.setKeepAliveSeconds(keepAliveSeconds);
//绛夊緟鎵�鏈変换鍔$粨鏉熷悗鍐嶅叧闂嚎绋嬫睜
executor.setWaitForTasksToCompleteOnShutdown(true);
//璁剧疆鎷掔粷绛栫暐
- //executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
+ executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
//鎵ц鍒濆鍖�
executor.initialize();
return executor;
diff --git a/ard-work/src/main/java/com/ruoyi/alarm/global/service/impl/GlobalAlarmServiceImpl.java b/ard-work/src/main/java/com/ruoyi/alarm/global/service/impl/GlobalAlarmServiceImpl.java
index 074021f..6d761a0 100644
--- a/ard-work/src/main/java/com/ruoyi/alarm/global/service/impl/GlobalAlarmServiceImpl.java
+++ b/ard-work/src/main/java/com/ruoyi/alarm/global/service/impl/GlobalAlarmServiceImpl.java
@@ -544,14 +544,12 @@
//鍒ゆ柇褰撳墠鎶ヨ鐐�5鍒嗛挓鍐呮槸鍚﹀凡寮曞
ardAlarmRadar.setGuideFlag(1);
- ArdAlarmRadar AlarmRadar = ardAlarmRadarMapper.getArdAlarmRadarWithGuide(ardAlarmRadar);
- // 缁撴潫鏃堕棿
- long etime = System.currentTimeMillis();
- // 璁$畻鎵ц鏃堕棿
- log.info("鏌ヨAPI鎵ц鏃堕暱锛�"+(etime-stime)+"姣");
+ // ArdAlarmRadar AlarmRadar = ardAlarmRadarMapper.getArdAlarmRadarWithGuide(ardAlarmRadar);
+ ArdAlarmRadar AlarmRadar = redisCache.getCacheObject("global_alarm:guideNew");//浠巖edis涓彇鍑烘渶鏂板紩瀵肩殑鎶ヨ鏁版嵁
if (StringUtils.isNull(AlarmRadar)) {
//5鍒嗛挓鍐呮湭寮曞鐩存帴鍏ュ簱
ardAlarmRadarMapper.insertArdAlarmRadar(ardAlarmRadar);
+ redisCache.setCacheObject("global_alarm:guideNew",ardAlarmRadar);//寮曞鏁版嵁鍐欏叆redis
//鑾峰彇闆疯揪鎵�鍦ㄥ涓婄殑澶у厜鐢�
String cameraIdWithTower = ardAlarmRadarMapper.getCameraByRadar(radarAlarmData.getRadarId());
if (StringUtils.isNotNull(cameraIdWithTower) && StringUtils.isNotEmpty(cameraIdWithTower)) {
@@ -563,7 +561,7 @@
ArdAlarmpointsWell ardAlarmpointsWell = ardAlarmpointsWellMapper.selectArdAlarmpointsWellByWellId(alarmpointName);
if (StringUtils.isNotNull(ardAlarmpointsWell) && StringUtils.isNotEmpty(ardAlarmpointsWell.getCameraId())) {
String cameraId = ardAlarmpointsWell.getCameraId();
- if (cameraIdWithTower.equals(cameraId)) {
+ if (cameraId.equals(cameraIdWithTower)) {
return;
}
log.info("鑾峰彇鍒版姤璀︾偣鍏宠仈鐨勫厜鐢�:" + cameraId);
@@ -578,6 +576,7 @@
if (count >= 3) {
ardAlarmRadar.setGuideFlag(1);
ardAlarmRadarMapper.insertArdAlarmRadar(ardAlarmRadar);
+ redisCache.setCacheObject("global_alarm:guideNew",ardAlarmRadar);//寮曞鏁版嵁鍐欏叆redis
//鑾峰彇闆疯揪鎵�鍦ㄥ涓婄殑澶у厜鐢�
String cameraIdWithTower = ardAlarmRadarMapper.getCameraByRadar(radarAlarmData.getRadarId());
if (StringUtils.isNotNull(cameraIdWithTower) && StringUtils.isNotEmpty(cameraIdWithTower)) {
@@ -601,6 +600,10 @@
ardAlarmRadarMapper.insertArdAlarmRadar(ardAlarmRadar);
}
}
+ // 缁撴潫鏃堕棿
+ long etime = System.currentTimeMillis();
+ // 璁$畻鎵ц鏃堕棿
+ log.info("鏌ヨAPI鎵ц鏃堕暱锛�"+(etime-stime)+"姣");
}
//endregion
@@ -736,8 +739,10 @@
private Boolean IsEnableGuide(String cameraId) {
boolean enabled = false;
ArdCameras ardCameras = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId);
- if (ardCameras.getCamAlarmGuideEnable().equals(1)) {
- enabled = true;
+ if(ardCameras!=null) {
+ if (ardCameras.getCamAlarmGuideEnable().equals(1)) {
+ enabled = true;
+ }
}
return enabled;
}
diff --git a/ard-work/src/main/java/com/ruoyi/test/ReadAccessDatabase.java b/ard-work/src/main/java/com/ruoyi/test/ReadAccessDatabase.java
index e146beb..4f6fa2e 100644
--- a/ard-work/src/main/java/com/ruoyi/test/ReadAccessDatabase.java
+++ b/ard-work/src/main/java/com/ruoyi/test/ReadAccessDatabase.java
@@ -15,17 +15,18 @@
public class ReadAccessDatabase {
public static void main(String[] args) {
- // 澶氫釜鏁版嵁搴撴枃浠惰矾寰�
- String[] dbPaths = {
- "D:\\mdb\\閬撹矾涓績绾�.mdb",
- "D:\\mdb\\闃查鏋�-鐏屾湪.mdb",
- // 娣诲姞鏇村鐨勬暟鎹簱鏂囦欢璺緞
- };
- // 閬嶅巻姣忎釜鏁版嵁搴撴枃浠�
- for (String dbPath : dbPaths) {
- readDataFromAccessDatabase(dbPath);
- }
+// // 澶氫釜鏁版嵁搴撴枃浠惰矾寰�
+// String[] dbPaths = {
+// "D:\\mdb\\閬撹矾涓績绾�.mdb",
+// "D:\\mdb\\闃查鏋�-鐏屾湪.mdb",
+// // 娣诲姞鏇村鐨勬暟鎹簱鏂囦欢璺緞
+// };
+//
+// // 閬嶅巻姣忎釜鏁版嵁搴撴枃浠�
+// for (String dbPath : dbPaths) {
+// readDataFromAccessDatabase(dbPath);
+// }
}
public static void readDataFromAccessDatabase(String dbPath) {
diff --git a/ruoyi-admin/src/main/java/com/ruoyi/RuoYiApplication.java b/ruoyi-admin/src/main/java/com/ruoyi/RuoYiApplication.java
index 957176f..1dd95b9 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/RuoYiApplication.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/RuoYiApplication.java
@@ -19,7 +19,7 @@
{
public static void main(String[] args)
{
- // System.setProperty("spring.devtools.restart.enabled", "false");
+ System.setProperty("spring.devtools.restart.enabled", "false");//鍏抽棴鐑儴缃�
SpringApplication.run(RuoYiApplication.class, args);
System.out.println("(鈾モ棤鈥库棤)锞夛緸 瀹夌憺杈�4.0骞冲彴鍚姩鎴愬姛 醿�(麓凇`醿�)锞� \n" +
" ___ ___ \n" +
diff --git a/ruoyi-admin/src/main/resources/application-ard.yml b/ruoyi-admin/src/main/resources/application-ard.yml
index a1e898d..1c15525 100644
--- a/ruoyi-admin/src/main/resources/application-ard.yml
+++ b/ruoyi-admin/src/main/resources/application-ard.yml
@@ -37,7 +37,14 @@
clientId: m3
username: admin
password: xzx12345
- topic: apponekey
+ topic: apponekey,radar
timeout: 100
keepalive: 60
- enabled: true
\ No newline at end of file
+ enabled: true
+
+#寮傛绾跨▼姹犻厤缃�
+ThreadPoolTask:
+ corePoolSize: 20
+ maxPoolSize: 40
+ keepAliveSeconds: 300
+ queueCapacity: 50
\ No newline at end of file
--
Gitblit v1.9.3