소스 검색

整合代码==去除多线程

syh 5 년 전
부모
커밋
88e2c5b29f

+ 1 - 24
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/job/KuaishouDailyReportTaskJob.java

@@ -13,9 +13,6 @@ import org.springframework.beans.factory.annotation.Autowired;
 
 import java.util.Date;
 import java.util.List;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
 
 @Slf4j
 public class KuaishouDailyReportTaskJob implements Job {
@@ -24,8 +21,6 @@ public class KuaishouDailyReportTaskJob implements Job {
     @Autowired
     private IKuaiShouHistoryReportTaskService reportTaskService;
 
-    private static ExecutorService executorService = Executors.newFixedThreadPool(3);
-    private static CountDownLatch countDownLatch = null;
     @Override
     public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
         log.info("快手获取日报数据任务执行开始");
@@ -37,26 +32,8 @@ public class KuaishouDailyReportTaskJob implements Job {
             return;
         }
         String getDateStr = DateUtils.formatDate(getDate);
-        countDownLatch = new CountDownLatch(tokens.size());
         for (CtopOauthToken token : tokens) {
-            executorService.submit(new Runnable() {
-                @Override
-                public void run() {
-                    //创建任务
-                    try {
-                        reportTaskService.createTask(token.getAccountId(), token.getAccessToken(), getDateStr, getDateStr, CtopAdConstant.KUAISHOU_LOAD_JOB_TYPE_DAILY);
-                    } catch (Exception e) {
-                        e.printStackTrace();
-                    } finally {
-                        countDownLatch.countDown();
-                    }
-                }
-            });
-        }
-        try {
-            countDownLatch.await();
-        } catch (InterruptedException e) {
-            e.printStackTrace();
+            reportTaskService.createTask(token.getAccountId(), token.getAccessToken(), getDateStr, getDateStr, CtopAdConstant.KUAISHOU_LOAD_JOB_TYPE_DAILY);
         }
         Long end = System.currentTimeMillis();
         log.info("快手获取日报数据任务执行结束,执行耗时:{}秒", (end - start) / 1000);

+ 1 - 1
jeecg-boot-module-system/src/test/java/org/jeecg/SampleTest.java

@@ -126,7 +126,7 @@ public class SampleTest {
                 public void run() {
                     //创建任务
                     try {
-//                        reportTaskService.createTask(token.getAccountId(), token.getAccessToken(), getDateStr);
+                        reportTaskService.createTask(token.getAccountId(), token.getAccessToken(), getDateStr, getDateStr, CtopAdConstant.KUAISHOU_LOAD_JOB_TYPE_DAILY);
                     } catch (Exception e) {
                         e.printStackTrace();
                     } finally {