Browse Source

修改匹配

xueyiming 8 months ago
parent
commit
93607d8062

+ 8 - 15
long-article-server/src/main/java/com/tzld/piaoquan/longarticle/service/local/impl/CoreServiceImpl.java

@@ -177,6 +177,14 @@ public class CoreServiceImpl implements CoreService {
 
     @Override
     public void matchContent() {
+
+        if (executorService.isShutdown() || executorService.isTerminated()) {
+            executorService = Executors.newFixedThreadPool(size);
+        } else {
+            executorService.shutdownNow();
+            executorService = Executors.newFixedThreadPool(size);
+        }
+
         // 启动生产者线程
         new Thread(() -> {
             List<PlanAccount> matchPlanAccounts = planAccountService.getMatchPlanAccount();
@@ -209,9 +217,6 @@ public class CoreServiceImpl implements CoreService {
             }
         }).start();
 
-        if (executorService.isShutdown() || executorService.isTerminated()) {
-            executorService = Executors.newFixedThreadPool(size);
-        }
 
         // 启动消费者线程
         for (int i = 0; i < size; i++) {
@@ -255,18 +260,6 @@ public class CoreServiceImpl implements CoreService {
                 }
             }));
         }
-
-        // 关闭线程池
-        Runtime.getRuntime().addShutdownHook(new Thread(() -> {
-            executorService.shutdown();
-            try {
-                if (!executorService.awaitTermination(10, TimeUnit.MINUTES)) {
-                    executorService.shutdownNow();
-                }
-            } catch (InterruptedException e) {
-                executorService.shutdownNow();
-            }
-        }));
     }