From 5b42d296274eae4b1af86a7f195decc0fab5e170 Mon Sep 17 00:00:00 2001 From: jianjun Date: Thu, 10 Sep 2020 10:03:01 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=80=E5=90=AF=E7=BA=BF=E7=A8=8B=E5=BC=82?= =?UTF-8?q?=E6=AD=A5=E8=AE=A1=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/IndexCalculateController.java | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/IndexCalculateController.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/IndexCalculateController.java index 003813df2b..e1e2c85d78 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/IndexCalculateController.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/IndexCalculateController.java @@ -8,6 +8,8 @@ import com.epmet.dto.indexcal.CalculateCommonFormDTO; import com.epmet.service.evaluationindex.indexcal.CpcIndexCalculateService; import com.epmet.service.evaluationindex.indexcal.IndexCalculateService; import com.epmet.util.DimIdGenerator; +import com.google.common.util.concurrent.ThreadFactoryBuilder; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PostMapping; @@ -16,6 +18,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.util.Date; +import java.util.concurrent.*; /** * 指标计算controller @@ -23,9 +26,16 @@ import java.util.Date; * @author liujianjun@elink-cn.com * @date 2020/8/24 14:38 */ +@Slf4j @RestController @RequestMapping("indexcalculate") public class IndexCalculateController { + ThreadFactory namedThreadFactory = new ThreadFactoryBuilder() + .setNameFormat("indexcalculate-pool-%d").build(); + ExecutorService singleThreadPool = new ThreadPoolExecutor(1, 1, + 0L, TimeUnit.MILLISECONDS, + new LinkedBlockingQueue(1024), namedThreadFactory, new ThreadPoolExecutor.AbortPolicy()); + @Autowired private IndexCalculateService indexCalculateService; @@ -44,12 +54,15 @@ public class IndexCalculateController { @ExternalAppRequestAuth @PostMapping("all") public Result indexCalculate(ExternalAppRequestParam externalAppRequestParam, @RequestBody CalculateCommonFormDTO formDTO) { - formDTO.setCustomerId(externalAppRequestParam.getCustomerId()); - Boolean aBoolean = indexCalculateService.indexCalculate(formDTO); - if (aBoolean) { - return new Result().ok(true); - } - return new Result().error("指标计算失败"); + singleThreadPool.execute(() -> { + formDTO.setCustomerId(externalAppRequestParam.getCustomerId()); + long start = System.currentTimeMillis(); + Boolean aBoolean = indexCalculateService.indexCalculate(formDTO); + if (aBoolean) { + log.error("全部指标计算完成,总耗时:{}秒", (System.currentTimeMillis() - start) / 1000); + } + }); + return new Result().ok(true); } @PostMapping("reAll")