Commit a9dd0c82 authored by tangwei's avatar tangwei

添加线程池

parent f9b381f8
package com.yeejoin.equipmanage.config;
import lombok.extern.slf4j.Slf4j;
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;
@Slf4j
@Configuration
@EnableAsync
public class EquipExecutorConfig {
@Bean(name = "equipAsyncExecutor")
public Executor asyncServiceExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
//配置核心线程数
executor.setCorePoolSize(10);
//配置最大线程数
executor.setMaxPoolSize(100);
//配置队列大小
executor.setQueueCapacity(1000);
//配置线程池中的线程的名称前缀
executor.setThreadNamePrefix("namePrefix");
//线程池维护线程所允许的空闲时间
executor.setKeepAliveSeconds(30);
// rejection-policy:当pool已经达到max size的时候,如何处理新任务
// CALLER_RUNS:不在新线程中执行任务,而是有调用者所在的线程来执行--拒绝策略
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
//执行初始化
executor.initialize();
//等待所有任务结束后再关闭线程池
executor.setWaitForTasksToCompleteOnShutdown(true);
return executor;
}
}
...@@ -236,7 +236,7 @@ public class CarController extends AbstractBaseController { ...@@ -236,7 +236,7 @@ public class CarController extends AbstractBaseController {
@Async @Async("equipAsyncExecutor")
public void refreshAllCount() { public void refreshAllCount() {
// 清空单位装备分类树缓存 // 清空单位装备分类树缓存
redisUtils.getAndDeletePatternKeys(carTypeAndCount + "*"); redisUtils.getAndDeletePatternKeys(carTypeAndCount + "*");
......
...@@ -127,7 +127,7 @@ public class EquipmentDetailController extends AbstractBaseController { ...@@ -127,7 +127,7 @@ public class EquipmentDetailController extends AbstractBaseController {
return detail; return detail;
} }
@Async @Async("equipAsyncExecutor")
public void refreshCount(String ...bizOrgCodes) { public void refreshCount(String ...bizOrgCodes) {
try { try {
equipmentSpecificSerivce.refreshStaData(); equipmentSpecificSerivce.refreshStaData();
...@@ -604,12 +604,23 @@ public class EquipmentDetailController extends AbstractBaseController { ...@@ -604,12 +604,23 @@ public class EquipmentDetailController extends AbstractBaseController {
@Async @Async("equipAsyncExecutor")
public void commonUpload(MultipartFile file, ExcelDto excelDto, String key, ReginParams reginParams, AgencyUserModel user) { public void commonUpload(MultipartFile file, ExcelDto excelDto, String key, ReginParams reginParams, AgencyUserModel user) {
synchronized(this.getClass()){ Object date="";
Object date=""; Map<String,Object> map=new HashMap();
date= excelService.commonUpload(file, excelDto, reginParams,user); try {
redisUtils.set(key, date); synchronized(this.getClass()){
date= excelService.commonUpload(file, excelDto, reginParams,user);
map.put("flag","0");
map.put("date",date);
redisUtils.set(key, map);
}
} catch (Exception e) {
map.put("flag","1");
map.put("date",e.getMessage());
redisUtils.set(key, map);
e.printStackTrace();
} }
} }
...@@ -628,7 +639,7 @@ public class EquipmentDetailController extends AbstractBaseController { ...@@ -628,7 +639,7 @@ public class EquipmentDetailController extends AbstractBaseController {
return ResponseHelper.buildResponse(null); return ResponseHelper.buildResponse(null);
} }
} }
@Async @Async("equipAsyncExecutor")
public void refreshAllCount() { public void refreshAllCount() {
// 清空单位装备分类树缓存 // 清空单位装备分类树缓存
redisUtils.getAndDeletePatternKeys(carTypeAndCount + "*"); redisUtils.getAndDeletePatternKeys(carTypeAndCount + "*");
......
...@@ -29,7 +29,7 @@ public class EquipmentTreeListListener implements ApplicationListener<EquipmentT ...@@ -29,7 +29,7 @@ public class EquipmentTreeListListener implements ApplicationListener<EquipmentT
@Autowired @Autowired
IEquipmentCategoryService iEquipmentCategoryService; IEquipmentCategoryService iEquipmentCategoryService;
@Async @Async("equipAsyncExecutor")
@Override @Override
public void onApplicationEvent(EquipmentTreeListEvent event) { public void onApplicationEvent(EquipmentTreeListEvent event) {
// 更新redis全量装备树 // 更新redis全量装备树
......
...@@ -1116,7 +1116,7 @@ public class CarServiceImpl extends ServiceImpl<CarMapper, Car> implements ICarS ...@@ -1116,7 +1116,7 @@ public class CarServiceImpl extends ServiceImpl<CarMapper, Car> implements ICarS
} }
@Override @Override
@Async @Async("equipAsyncExecutor")
public FireVehicle getFireVehicleDetailById(Long id) { public FireVehicle getFireVehicleDetailById(Long id) {
return carMapper.getFireVehicleDetailById(id); return carMapper.getFireVehicleDetailById(id);
} }
...@@ -1187,7 +1187,7 @@ public class CarServiceImpl extends ServiceImpl<CarMapper, Car> implements ICarS ...@@ -1187,7 +1187,7 @@ public class CarServiceImpl extends ServiceImpl<CarMapper, Car> implements ICarS
return ""; return "";
} }
@Async @Async("equipAsyncExecutor")
void dataSyncSaveOrUpdate(Car car) { void dataSyncSaveOrUpdate(Car car) {
CarIndexVo carIndexVo = new CarIndexVo(); CarIndexVo carIndexVo = new CarIndexVo();
carIndexVo.setId(car.getId()); carIndexVo.setId(car.getId());
......
...@@ -1157,7 +1157,7 @@ public class EquipmentSpecificSerivceImpl extends ServiceImpl<EquipmentSpecificM ...@@ -1157,7 +1157,7 @@ public class EquipmentSpecificSerivceImpl extends ServiceImpl<EquipmentSpecificM
} }
@Override @Override
@Async @Async("equipAsyncExecutor")
public void equipSpecificDataSync(Long equipmentId) { public void equipSpecificDataSync(Long equipmentId) {
// TODO 放大范围,根据equipment_id同步 // TODO 放大范围,根据equipment_id同步
List<FireEquipment> specificDetails = getEquipSpecificDetailsByEquipmentId(equipmentId); List<FireEquipment> specificDetails = getEquipSpecificDetailsByEquipmentId(equipmentId);
...@@ -1548,7 +1548,7 @@ public class EquipmentSpecificSerivceImpl extends ServiceImpl<EquipmentSpecificM ...@@ -1548,7 +1548,7 @@ public class EquipmentSpecificSerivceImpl extends ServiceImpl<EquipmentSpecificM
equipmentSpecificIndexSerivce.saveBatch(equipmentSpecificIndices); equipmentSpecificIndexSerivce.saveBatch(equipmentSpecificIndices);
} }
@Async @Async("equipAsyncExecutor")
void initEquipmentSystemSourceStatistics(List<EquipmentSpecific> equipmentSpecifics) { void initEquipmentSystemSourceStatistics(List<EquipmentSpecific> equipmentSpecifics) {
List<EquipmentSystemSourceStatistics> list = new ArrayList<>(); List<EquipmentSystemSourceStatistics> list = new ArrayList<>();
equipmentSpecifics.parallelStream().forEach(x -> { equipmentSpecifics.parallelStream().forEach(x -> {
...@@ -1600,7 +1600,7 @@ public class EquipmentSpecificSerivceImpl extends ServiceImpl<EquipmentSpecificM ...@@ -1600,7 +1600,7 @@ public class EquipmentSpecificSerivceImpl extends ServiceImpl<EquipmentSpecificM
* *
* @param systemTypeCode * @param systemTypeCode
*/ */
@Async @Async("equipAsyncExecutor")
@Override @Override
public void integrationPageSysDataRefresh(String systemTypeCode) { public void integrationPageSysDataRefresh(String systemTypeCode) {
if (ObjectUtils.isEmpty(systemTypeCode)) { if (ObjectUtils.isEmpty(systemTypeCode)) {
......
...@@ -288,7 +288,7 @@ public class MainIotMonitorServiceImpl implements IMainIotMonitorSerivce { ...@@ -288,7 +288,7 @@ public class MainIotMonitorServiceImpl implements IMainIotMonitorSerivce {
} }
} }
@Async @Async("equipAsyncExecutor")
void updateEquipmentSystemSourceStatistics(EquipmentSpecific equipmentSpecific, int status){ void updateEquipmentSystemSourceStatistics(EquipmentSpecific equipmentSpecific, int status){
QueryWrapper<EquipmentSystemSourceStatistics> wrapper = new QueryWrapper<>(); QueryWrapper<EquipmentSystemSourceStatistics> wrapper = new QueryWrapper<>();
wrapper.eq("equipment_specific_id",equipmentSpecific.getId()); wrapper.eq("equipment_specific_id",equipmentSpecific.getId());
......
...@@ -133,7 +133,7 @@ public class MaintenanceResourceDataServiceImpl extends ServiceImpl<MaintenanceR ...@@ -133,7 +133,7 @@ public class MaintenanceResourceDataServiceImpl extends ServiceImpl<MaintenanceR
return 0; return 0;
} }
@Async @Async("equipAsyncExecutor")
void deleteRelationMainResData(List<Long> ids) { void deleteRelationMainResData(List<Long> ids) {
try { try {
maintenanceFeign.pointDelete(Joiner.on(",").join(ids)); maintenanceFeign.pointDelete(Joiner.on(",").join(ids));
......
...@@ -266,7 +266,7 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements ...@@ -266,7 +266,7 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
return stockBill; return stockBill;
} }
@Async @Async("equipAsyncExecutor")
void initEquipmentSystemSourceStatistics(List<EquipmentSpecific> equipmentSpecifics) { void initEquipmentSystemSourceStatistics(List<EquipmentSpecific> equipmentSpecifics) {
List<EquipmentSystemSourceStatistics> list = new ArrayList<>(); List<EquipmentSystemSourceStatistics> list = new ArrayList<>();
equipmentSpecifics.parallelStream().forEach(x -> { equipmentSpecifics.parallelStream().forEach(x -> {
......
...@@ -59,7 +59,7 @@ import com.yeejoin.equipmanage.utils.SyncDataUtil; ...@@ -59,7 +59,7 @@ import com.yeejoin.equipmanage.utils.SyncDataUtil;
* @Date 2021-04-01 14:28 * @Date 2021-04-01 14:28
*/ */
@Service("syncDataService") @Service("syncDataService")
@Async @Async("equipAsyncExecutor")
public class SyncDataServiceImpl implements ISyncDataService { public class SyncDataServiceImpl implements ISyncDataService {
private final Logger logger = LoggerFactory.getLogger(SyncDataServiceImpl.class); private final Logger logger = LoggerFactory.getLogger(SyncDataServiceImpl.class);
...@@ -511,7 +511,7 @@ public class SyncDataServiceImpl implements ISyncDataService { ...@@ -511,7 +511,7 @@ public class SyncDataServiceImpl implements ISyncDataService {
} }
} }
@Async @Async("equipAsyncExecutor")
@Override @Override
public void saveOrUpdateEquipIotCodeRedisData(List<EquipmentSpecificVo> data) { public void saveOrUpdateEquipIotCodeRedisData(List<EquipmentSpecificVo> data) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
......
...@@ -34,7 +34,7 @@ public class RelationRedisUtil { ...@@ -34,7 +34,7 @@ public class RelationRedisUtil {
@Autowired @Autowired
private FireFightingSystemMapper fireFightingSystemMapper; private FireFightingSystemMapper fireFightingSystemMapper;
@Async @Async("equipAsyncExecutor")
public Boolean delSysRedisKey(String systemId) { public Boolean delSysRedisKey(String systemId) {
if (StringUtils.isNotBlank(systemId)) { if (StringUtils.isNotBlank(systemId)) {
QueryWrapper<FireFightingSystemEntity> queryWrapper = new QueryWrapper<>(); QueryWrapper<FireFightingSystemEntity> queryWrapper = new QueryWrapper<>();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment