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 {
@Async
@Async("equipAsyncExecutor")
public void refreshAllCount() {
// 清空单位装备分类树缓存
redisUtils.getAndDeletePatternKeys(carTypeAndCount + "*");
......
......@@ -127,7 +127,7 @@ public class EquipmentDetailController extends AbstractBaseController {
return detail;
}
@Async
@Async("equipAsyncExecutor")
public void refreshCount(String ...bizOrgCodes) {
try {
equipmentSpecificSerivce.refreshStaData();
......@@ -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) {
synchronized(this.getClass()){
Object date="";
Map<String,Object> map=new HashMap();
try {
synchronized(this.getClass()){
date= excelService.commonUpload(file, excelDto, reginParams,user);
redisUtils.set(key, date);
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 {
return ResponseHelper.buildResponse(null);
}
}
@Async
@Async("equipAsyncExecutor")
public void refreshAllCount() {
// 清空单位装备分类树缓存
redisUtils.getAndDeletePatternKeys(carTypeAndCount + "*");
......
......@@ -29,7 +29,7 @@ public class EquipmentTreeListListener implements ApplicationListener<EquipmentT
@Autowired
IEquipmentCategoryService iEquipmentCategoryService;
@Async
@Async("equipAsyncExecutor")
@Override
public void onApplicationEvent(EquipmentTreeListEvent event) {
// 更新redis全量装备树
......
......@@ -1116,7 +1116,7 @@ public class CarServiceImpl extends ServiceImpl<CarMapper, Car> implements ICarS
}
@Override
@Async
@Async("equipAsyncExecutor")
public FireVehicle getFireVehicleDetailById(Long id) {
return carMapper.getFireVehicleDetailById(id);
}
......@@ -1187,7 +1187,7 @@ public class CarServiceImpl extends ServiceImpl<CarMapper, Car> implements ICarS
return "";
}
@Async
@Async("equipAsyncExecutor")
void dataSyncSaveOrUpdate(Car car) {
CarIndexVo carIndexVo = new CarIndexVo();
carIndexVo.setId(car.getId());
......
......@@ -1157,7 +1157,7 @@ public class EquipmentSpecificSerivceImpl extends ServiceImpl<EquipmentSpecificM
}
@Override
@Async
@Async("equipAsyncExecutor")
public void equipSpecificDataSync(Long equipmentId) {
// TODO 放大范围,根据equipment_id同步
List<FireEquipment> specificDetails = getEquipSpecificDetailsByEquipmentId(equipmentId);
......@@ -1548,7 +1548,7 @@ public class EquipmentSpecificSerivceImpl extends ServiceImpl<EquipmentSpecificM
equipmentSpecificIndexSerivce.saveBatch(equipmentSpecificIndices);
}
@Async
@Async("equipAsyncExecutor")
void initEquipmentSystemSourceStatistics(List<EquipmentSpecific> equipmentSpecifics) {
List<EquipmentSystemSourceStatistics> list = new ArrayList<>();
equipmentSpecifics.parallelStream().forEach(x -> {
......@@ -1600,7 +1600,7 @@ public class EquipmentSpecificSerivceImpl extends ServiceImpl<EquipmentSpecificM
*
* @param systemTypeCode
*/
@Async
@Async("equipAsyncExecutor")
@Override
public void integrationPageSysDataRefresh(String systemTypeCode) {
if (ObjectUtils.isEmpty(systemTypeCode)) {
......
......@@ -288,7 +288,7 @@ public class MainIotMonitorServiceImpl implements IMainIotMonitorSerivce {
}
}
@Async
@Async("equipAsyncExecutor")
void updateEquipmentSystemSourceStatistics(EquipmentSpecific equipmentSpecific, int status){
QueryWrapper<EquipmentSystemSourceStatistics> wrapper = new QueryWrapper<>();
wrapper.eq("equipment_specific_id",equipmentSpecific.getId());
......
......@@ -133,7 +133,7 @@ public class MaintenanceResourceDataServiceImpl extends ServiceImpl<MaintenanceR
return 0;
}
@Async
@Async("equipAsyncExecutor")
void deleteRelationMainResData(List<Long> ids) {
try {
maintenanceFeign.pointDelete(Joiner.on(",").join(ids));
......
......@@ -266,7 +266,7 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
return stockBill;
}
@Async
@Async("equipAsyncExecutor")
void initEquipmentSystemSourceStatistics(List<EquipmentSpecific> equipmentSpecifics) {
List<EquipmentSystemSourceStatistics> list = new ArrayList<>();
equipmentSpecifics.parallelStream().forEach(x -> {
......
......@@ -59,7 +59,7 @@ import com.yeejoin.equipmanage.utils.SyncDataUtil;
* @Date 2021-04-01 14:28
*/
@Service("syncDataService")
@Async
@Async("equipAsyncExecutor")
public class SyncDataServiceImpl implements ISyncDataService {
private final Logger logger = LoggerFactory.getLogger(SyncDataServiceImpl.class);
......@@ -511,7 +511,7 @@ public class SyncDataServiceImpl implements ISyncDataService {
}
}
@Async
@Async("equipAsyncExecutor")
@Override
public void saveOrUpdateEquipIotCodeRedisData(List<EquipmentSpecificVo> data) {
// TODO Auto-generated method stub
......
......@@ -34,7 +34,7 @@ public class RelationRedisUtil {
@Autowired
private FireFightingSystemMapper fireFightingSystemMapper;
@Async
@Async("equipAsyncExecutor")
public Boolean delSysRedisKey(String systemId) {
if (StringUtils.isNotBlank(systemId)) {
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