Browse Source

1.增加了多个线程池,用于区分各个任务线程

verguenza 4 years ago
parent
commit
e4aa372915

+ 35 - 0
src/main/java/com/galaxis/manatee/configuration/SpringAsyncConfiguration.java

@@ -1,7 +1,11 @@
 package com.galaxis.manatee.configuration;
 
+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;
 
 /**
  * @author zcj
@@ -11,4 +15,35 @@ import org.springframework.scheduling.annotation.EnableAsync;
 @Configuration
 @EnableAsync
 public class SpringAsyncConfiguration {
+
+    @Bean(name = "taskExecutor")
+    public Executor taskExecutor()
+    {
+        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
+        return executor;
+    }
+
+    @Bean(name = "updateExecutor")
+    public Executor updateExecutor()
+    {
+        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
+        executor.setCorePoolSize(3);
+        executor.setMaxPoolSize(50000);
+        executor.setQueueCapacity(100);
+        executor.setThreadNamePrefix("updateExecutor-");
+        executor.initialize();
+        return executor;
+    }
+
+    @Bean(name = "standardExecutor")
+    public Executor standardExecutor()
+    {
+        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
+        executor.setCorePoolSize(3);
+        executor.setMaxPoolSize(50000);
+        executor.setQueueCapacity(100);
+        executor.setThreadNamePrefix("standardExecutor-");
+        executor.initialize();
+        return executor;
+    }
 }

+ 9 - 12
src/main/java/com/galaxis/manatee/controller/GetController.java

@@ -8,10 +8,7 @@ import com.galaxis.manatee.service.ChuanyunService;
 import com.galaxis.manatee.task.ChuanyunBasicDataScheduledTask;
 import com.galaxis.manatee.task.ChuanyunHumanResourceScheduledTask;
 import com.galaxis.manatee.util.ExcelUtils;
-import lombok.Data;
 import lombok.extern.slf4j.Slf4j;
-import net.sf.json.JSON;
-import net.sf.json.JSONObject;
 import org.springframework.http.ResponseEntity;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.web.bind.annotation.*;
@@ -42,7 +39,7 @@ public class GetController {
     /**
      * 手动更新chuanyunPayRoll
      */
-    @Async
+    @Async("taskExecutor")
     @GetMapping("/test/getChuanyunPayroll")
     public void getChuanyunPayroll(){
         chuanyunHumanResourceScheduledTask.getPayrollManually();
@@ -51,7 +48,7 @@ public class GetController {
     /**
      * 手动更新日志
      */
-    @Async
+    @Async("taskExecutor")
     @GetMapping("/test/getUpdateLog")
     public void getUpdateLog() {
         chuanyunHumanResourceScheduledTask.getUpdateLog();
@@ -60,7 +57,7 @@ public class GetController {
     /**
      * 手动更新项目组成员
      */
-    @Async
+    @Async("taskExecutor")
     @GetMapping("/test/getProjectMember")
     public void getProjectMember() {
         chuanyunService.updateProjectMember();
@@ -69,7 +66,7 @@ public class GetController {
     /**
      * 手动更新人员-归属公司
      */
-    @Async
+    @Async("taskExecutor")
     @GetMapping("/test/getUserCompany")
     public void getUserCompanyManually() {
         chuanyunBasicDataScheduledTask.getUserCompanyManually();
@@ -78,7 +75,7 @@ public class GetController {
     /**
      * 手动更新人员信息
      */
-    @Async
+    @Async("taskExecutor")
     @GetMapping("/test/getUserList")
     public void getUserListManually() {
         chuanyunBasicDataScheduledTask.getUserListManually();
@@ -87,7 +84,7 @@ public class GetController {
     /**
      * 手动更新公司信息
      */
-    @Async
+    @Async("taskExecutor")
     @GetMapping("/test/getCompany")
     public void getCompanyManually() {
         chuanyunBasicDataScheduledTask.getCompanyManually();
@@ -96,19 +93,19 @@ public class GetController {
     /**
      * 手动更新集团项目信息
      */
-    @Async
+    @Async("taskExecutor")
     @GetMapping("/test/getGroupProject")
     public void getGroupProjectManually() {
         chuanyunBasicDataScheduledTask.getGroupProjectManually();
     }
 
-    @Async
+    @Async("taskExecutor")
     @GetMapping("/test/getCostCollectionManually")
     public void getCostCollectionManually() {
         chuanyunBasicDataScheduledTask.getCostCollectionManually();
     }
 
-    @Async
+    @Async("taskExecutor")
     @GetMapping("/test/getReimbursementItemsManually")
     public void getReimbursementItemsManually() {
         chuanyunBasicDataScheduledTask.getReimbursementItemsManually();

+ 5 - 5
src/main/java/com/galaxis/manatee/service/DataArcherService.java

@@ -34,7 +34,7 @@ public class DataArcherService {
     /**
      * 异步更新每日工时
      */
-    @Async
+    @Async("updateExecutor")
     public void updateSelfWorkHour(ChuanyunSelfWorkHourDTO chuanyunSelfWorkHourDTO) {
         ObjectMapper objectMapper = new ObjectMapper();
         try {
@@ -76,7 +76,7 @@ public class DataArcherService {
      *
      * @param chuanyunWeekMemberHourDTO 每周工时数据对象
      */
-    @Async
+    @Async("updateExecutor")
     public void updateWeekMemberHour(ChuanyunWeekMemberHourDTO chuanyunWeekMemberHourDTO) {
         ObjectMapper objectMapper = new ObjectMapper();
         try {
@@ -113,7 +113,7 @@ public class DataArcherService {
      *
      * @param chuanyunSelfCostDTO 每周工时数据对象
      */
-    @Async
+    @Async("updateExecutor")
     public void updateChuanyunSelfCost(ChuanyunSelfCostDTO chuanyunSelfCostDTO) {
         ObjectMapper objectMapper = new ObjectMapper();
         try {
@@ -148,7 +148,7 @@ public class DataArcherService {
      * 删除审核中的每月工时
      * @param chuanyunSelfCostDO    氚云每月工时
      */
-    @Async
+    @Async("updateExecutor")
     public void deleteSelfCostInProcess(ChuanyunSelfCostDO chuanyunSelfCostDO) {
         ObjectMapper objectMapper=new ObjectMapper();
         //删除氚云中的在审核工时
@@ -181,7 +181,7 @@ public class DataArcherService {
     /**
      * 删除状态为审核中数据
      */
-    @Async
+    @Async("updateExecutor")
     public void deleteExamineStatus(String schemaCode, String statusCode, String projectCode, String projectId, String userCode, String userId, String yearCode, String year, String monthCode, String month, String weekCode, String week, String typeCode, String projectType) {
         ObjectMapper objectMapper = new ObjectMapper();
         try {

+ 4 - 4
src/main/java/com/galaxis/manatee/service/LogStandardService.java

@@ -50,7 +50,7 @@ public class LogStandardService {
      * @param isRecent              是否只标准化最近一个月的数据
      * @param chuanyunUserCompanyDO 员工信息
      */
-    @Async
+    @Async("standardExecutor")
     public void standardHourByUserCompanyAndIsRecent(ChuanyunUserCompanyDO chuanyunUserCompanyDO, boolean isRecent) {
         if (!StringUtils.isEmpty(chuanyunUserCompanyDO.getUserId())) {
             long start = Instant.now().getEpochSecond();
@@ -68,7 +68,7 @@ public class LogStandardService {
      * 根据用户Id标准化某个人的日工时
      * @param userId    用户Id
      */
-    @Async
+    @Async("standardExecutor")
     public void standardSelfWorkHourByUserId(String userId){
         if (!StringUtils.isEmpty(userId)) {
             //从日志原始数据中获取每人每个项目每天工时。
@@ -83,7 +83,7 @@ public class LogStandardService {
      * 根据用户Id标准化某个人的工时
      * @param userId    用户Id
      */
-    @Async
+    @Async("standardExecutor")
     public void standardWeekMemberHourByUserId(String userId){
         if (!StringUtils.isEmpty(userId)) {
             long start=Instant.now().getEpochSecond();
@@ -102,7 +102,7 @@ public class LogStandardService {
      * 2.将新工时数据保存在manatee中
      * @param userId    用户Id
      */
-    @Async
+    @Async("standardExecutor")
     public void standardSelfCostByUserId(String userId){
         long start=Instant.now().getEpochSecond();
         //删除上一次状态为审核中,但本次已经审核通过的数据

+ 3 - 5
src/main/java/com/galaxis/manatee/service/ProjectMemberService.java

@@ -3,10 +3,8 @@ package com.galaxis.manatee.service;
 import com.fasterxml.jackson.core.type.TypeReference;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.galaxis.manatee.dao.ChuanyunGroupProjectDao;
-import com.galaxis.manatee.entity.chuanyun.data.object.ChuanyunDevelopProjectDO;
 import com.galaxis.manatee.entity.chuanyun.data.object.ChuanyunGroupProjectDO;
 import com.galaxis.manatee.entity.chuanyun.data.object.ChuanyunManagerProjectDO;
-import com.galaxis.manatee.entity.chuanyun.data.object.ChuanyunSaleProjectDO;
 import com.galaxis.manatee.entity.chuanyun.dto.ChuanyunFindAllBizDTO;
 import com.galaxis.manatee.entity.chuanyun.dto.Filter;
 import com.galaxis.manatee.manager.ChuanYunManager;
@@ -33,7 +31,7 @@ public class ProjectMemberService {
         this.chuanyunGroupProjectDao = chuanyunGroupProjectDao;
     }
 
-    @Async
+    @Async("taskExecutor")
     public void updateManagerMember(String param) throws InterruptedException {
         TimeUnit.SECONDS.sleep(5);
         log.info("同步管理项目组成员");
@@ -65,7 +63,7 @@ public class ProjectMemberService {
         }
     }
 
-    @Async
+    @Async("taskExecutor")
     public void updateSaleMember(String param) throws InterruptedException {
         TimeUnit.SECONDS.sleep(5);
         log.info("同步销售项目组成员");
@@ -93,7 +91,7 @@ public class ProjectMemberService {
         }
     }
 
-    @Async
+    @Async("taskExecutor")
     public void updateDevelopMember(String param) throws InterruptedException {
         TimeUnit.SECONDS.sleep(5);
         log.info("同步研发项目组成员");

+ 1 - 1
src/main/java/com/galaxis/manatee/task/WorkHourStatistics.java

@@ -68,7 +68,7 @@ public class WorkHourStatistics {
      * 更新所有项目工时
      */
 //    @Scheduled(fixedDelay = 432000000L)
-    @Async
+    @Async("standardExecutor")
     public void standardHour() {
         //每日工时标准化
         standardWorkHour();