1.使用自定义线程池,对feign调用的接口进行异步调用
master
陈江保 3 months ago
parent 4fa818b98c
commit 5f697ceb21
  1. 52
      src/main/java/digital/laboratory/platform/entrustment/config/GlobalThreadPool.java
  2. 25
      src/main/java/digital/laboratory/platform/entrustment/service/impl/EntrustmentServiceImpl.java

@ -0,0 +1,52 @@
package digital.laboratory.platform.entrustment.config;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import javax.annotation.PreDestroy;
import java.util.concurrent.*;
/**
* 定义全局线程池
*/
@Slf4j
@Component
public class GlobalThreadPool {
// 定义全局线程池,使用单列模式
private static final ExecutorService THREAD_POOL = new ThreadPoolExecutor(
10, // 核心线程数
50, // 最大线程数
60L, TimeUnit.SECONDS, // 空闲线程存活时间
new LinkedBlockingQueue<Runnable>(100), // 任务队列
Executors.defaultThreadFactory(), // 线程工厂
new ThreadPoolExecutor.CallerRunsPolicy() // 拒绝策略
);
// 私有化构造方法,防止外部实例化
private GlobalThreadPool() {}
// 获取全局线程池实列
public static ExecutorService getInstance() {
return THREAD_POOL;
}
// 关闭线程池
public static void shutdown() {
THREAD_POOL.shutdown();
}
// 在应用关闭前执行
@PreDestroy
public void destroy() {
log.info("Spring 应用关闭,正在关闭线程池...");
shutdown();
try {
if (!THREAD_POOL.awaitTermination(60, TimeUnit.SECONDS)) {
THREAD_POOL.shutdownNow();
}
} catch (InterruptedException e) {
THREAD_POOL.shutdownNow();
}
}
}

@ -31,6 +31,7 @@ import digital.laboratory.platform.common.feign.RemoteWord2PDFService;
import digital.laboratory.platform.common.mybatis.security.service.DLPUser; import digital.laboratory.platform.common.mybatis.security.service.DLPUser;
import digital.laboratory.platform.common.oss.service.OssFile; import digital.laboratory.platform.common.oss.service.OssFile;
import digital.laboratory.platform.common.security.util.SecurityUtils; import digital.laboratory.platform.common.security.util.SecurityUtils;
import digital.laboratory.platform.entrustment.config.GlobalThreadPool;
import digital.laboratory.platform.entrustment.constant.EntrustMarkConstants; import digital.laboratory.platform.entrustment.constant.EntrustMarkConstants;
import digital.laboratory.platform.entrustment.convert.DrugLiteConvert; import digital.laboratory.platform.entrustment.convert.DrugLiteConvert;
import digital.laboratory.platform.entrustment.dto.EntrustmentDTO; import digital.laboratory.platform.entrustment.dto.EntrustmentDTO;
@ -78,6 +79,7 @@ import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.*; import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function; import java.util.function.Function;
import java.util.function.Predicate; import java.util.function.Predicate;
@ -2964,7 +2966,7 @@ public class EntrustmentServiceImpl extends ServiceImpl<EntrustmentMapper, Entru
Integer entrustmentIdentificationMaterialQuantity = 0; Integer entrustmentIdentificationMaterialQuantity = 0;
Integer acceptanceIdentificationMaterialQuantity = 0; Integer acceptanceIdentificationMaterialQuantity = 0;
Integer sewageJobIdentificationMaterialQuantity = 0;
Integer hairJobIdentificationMaterialQuantity = 0; Integer hairJobIdentificationMaterialQuantity = 0;
//查询这个账户(机构)下的所有委托中的所有已受理检材的数量 //查询这个账户(机构)下的所有委托中的所有已受理检材的数量
@ -2976,16 +2978,17 @@ public class EntrustmentServiceImpl extends ServiceImpl<EntrustmentMapper, Entru
} }
markersVOS.add(new MarkersVO("案件委托检材", entrustmentIdentificationMaterialQuantity, "", "EntrustmentCreate")); markersVOS.add(new MarkersVO("案件委托检材", entrustmentIdentificationMaterialQuantity, "", "EntrustmentCreate"));
CompletableFuture.runAsync(() -> {
R<Integer> imQuantity = remoteSewageJobService.getIMQuantity(dlpUser.getOrgId()); Integer sewageJobIdentificationMaterialQuantity = 0;
if (imQuantity.getCode() == CommonConstants.SUCCESS) { R<Integer> imQuantity = remoteSewageJobService.getIMQuantity(dlpUser.getOrgId());
sewageJobIdentificationMaterialQuantity = imQuantity.getData(); if (imQuantity.getCode() == CommonConstants.SUCCESS) {
} else { sewageJobIdentificationMaterialQuantity = imQuantity.getData();
log.error("查询这个账户(机构)下面所送检且已受理的所有污水检材的数量 失败!失败原因:{}", imQuantity.getMsg()); } else {
sewageJobIdentificationMaterialQuantity = 0; log.error("查询这个账户(机构)下面所送检且已受理的所有污水检材的数量 失败!失败原因:{}", imQuantity.getMsg());
} sewageJobIdentificationMaterialQuantity = 0;
markersVOS.add(new MarkersVO("污水送检检材", sewageJobIdentificationMaterialQuantity, "", "SewageJobGet")); }
markersVOS.add(new MarkersVO("污水送检检材", sewageJobIdentificationMaterialQuantity, "", "SewageJobGet"));
}, GlobalThreadPool.getInstance());
try { try {
R<Integer> sampleQuantity = remoteHairJobService.getSampleQuantity(orgId, 2); R<Integer> sampleQuantity = remoteHairJobService.getSampleQuantity(orgId, 2);

Loading…
Cancel
Save