Pārlūkot izejas kodu

加入多线程

yumeng 5 gadi atpakaļ
vecāks
revīzija
4412132503

+ 56 - 25
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/TestController.java

@@ -60,6 +60,9 @@ public class TestController {
     private IMaterialImageInfoService iMaterialImageInfoService;
     @Autowired
     private IBytedanceReportService bytedanceReportService;
+    static ExecutorService executorService = Executors.newFixedThreadPool(10);
+    static ExecutorService videoService = Executors.newFixedThreadPool(5);
+    static ExecutorService suzhaoService = Executors.newFixedThreadPool(5);
 
     @GetMapping(value = "/t")
     public String test() {
@@ -100,38 +103,66 @@ public class TestController {
 
     @GetMapping(value = "/getVideoTime")
     public void getVideoTime() throws InterruptedException {
-        QueryWrapper<KuaiShouVideoGet> queryWrapper = new QueryWrapper<>();
-        queryWrapper.eq("channel_type", 0);
-        List<KuaiShouVideoGet> list = videoGetService.list(queryWrapper);
-        for (KuaiShouVideoGet video : list) {
-            Date date = timeService.getVideoTime(video.getPhotoId(), video.getAccountId());
-            if (Check.isNull(date)) {
-                continue;
-            }
-            video.setUploadDate(date);
-            videoGetService.updateById(video);
-            Thread.sleep(100);
+        Thread thread = new Thread() {
+            @Override
+            public void run() {
+                QueryWrapper<KuaiShouVideoGet> queryWrapper = new QueryWrapper<>();
+                queryWrapper.eq("channel_type", 0);
+                List<KuaiShouVideoGet> list = videoGetService.list(queryWrapper);
+                for (KuaiShouVideoGet video : list) {
+                    videoService.submit(new Runnable() {
+                        @Override
+                        public void run() {
+                            Date date = timeService.getVideoTime(video.getPhotoId(), video.getAccountId());
+                            if (!Check.isNull(date)) {
+                                video.setUploadDate(date);
+                                videoGetService.updateById(video);
+                            }
 
-        }
+                            try {
+                                Thread.sleep(400);
+                            } catch (InterruptedException e) {
+                                e.printStackTrace();
+                            }
+                        }
+                    });
+                }
+            }
+        };
+        thread.start();
 
     }
 
 
     @GetMapping(value = "/getSuZhao")
     public void getSuZhao() throws InterruptedException {
-        QueryWrapper<KuaiShouVideoGet> queryWrapper = new QueryWrapper<>();
-        queryWrapper.eq("channel_type", 1);
-        List<KuaiShouVideoGet> list = videoGetService.list(queryWrapper);
-        for (KuaiShouVideoGet video : list) {
-            Date date = timeService.getVideoTime(video.getPhotoId(), video.getAccountId());
-            if (Check.isNull(date)) {
-                continue;
-            }
-            video.setUploadDate(date);
-            videoGetService.updateById(video);
-            Thread.sleep(100);
+        Thread thread = new Thread() {
+            @Override
+            public void run() {
+                QueryWrapper<KuaiShouVideoGet> queryWrapper = new QueryWrapper<>();
+                queryWrapper.eq("channel_type", 1);
+                List<KuaiShouVideoGet> list = videoGetService.list(queryWrapper);
+                for (KuaiShouVideoGet video : list) {
+                    suzhaoService.submit(new Runnable() {
+                        @Override
+                        public void run() {
+                            Date date = timeService.getVideoTime(video.getPhotoId(), video.getAccountId());
+                            if (!Check.isNull(date)) {
+                                video.setUploadDate(date);
+                                videoGetService.updateById(video);
+                            }
 
-        }
+                            try {
+                                Thread.sleep(400);
+                            } catch (InterruptedException e) {
+                                e.printStackTrace();
+                            }
+                        }
+                    });
+                }
+            }
+        };
+        thread.start();
 
     }
 
@@ -445,7 +476,7 @@ public class TestController {
         return "Success";
     }
 
-    static ExecutorService executorService = Executors.newFixedThreadPool(10);
+
 
 
     @GetMapping(value = "/gerCreative")