wangliang 1 долоо хоног өмнө
parent
commit
0e838356d9

+ 4 - 8
src/main/java/com/qmth/cet/plug/api/CetPlugController.java

@@ -47,6 +47,9 @@ public class CetPlugController {
     @Value("${com.qmth.cet6.dir}")
     @Value("${com.qmth.cet6.dir}")
     String cet6Dir;
     String cet6Dir;
 
 
+    @Value("${com.qmth.client.dir}")
+    String clientDir;
+
     @Resource
     @Resource
     LogicService logicService;
     LogicService logicService;
 
 
@@ -60,14 +63,7 @@ public class CetPlugController {
         int cpuNum = Runtime.getRuntime().availableProcessors();
         int cpuNum = Runtime.getRuntime().availableProcessors();
         ExecutorService executor = Executors.newFixedThreadPool(Math.abs(cpuNum / 2));
         ExecutorService executor = Executors.newFixedThreadPool(Math.abs(cpuNum / 2));
         if (Objects.nonNull(cet4Dir)) {
         if (Objects.nonNull(cet4Dir)) {
-            logicService.execFile(cet4Dir, projectPath, "cet4");
-//            executor.submit(() -> {
-//                try {
-//                    SystemConstant.execFile(cet4Dir, projectPath, "cet4");
-//                } catch (IOException e) {
-//                    e.printStackTrace();
-//                }
-//            });
+            logicService.execFile(cet4Dir, projectPath, "cet4", executor);
         }
         }
         executor.shutdown();
         executor.shutdown();
         while (!executor.awaitTermination(1, TimeUnit.MINUTES)) {
         while (!executor.awaitTermination(1, TimeUnit.MINUTES)) {

+ 3 - 1
src/main/java/com/qmth/cet/plug/service/LogicService.java

@@ -1,6 +1,7 @@
 package com.qmth.cet.plug.service;
 package com.qmth.cet.plug.service;
 
 
 import java.io.IOException;
 import java.io.IOException;
+import java.util.concurrent.ExecutorService;
 
 
 /**
 /**
  * @Description: logic service
  * @Description: logic service
@@ -17,6 +18,7 @@ public interface LogicService {
      * @param fileName
      * @param fileName
      * @param projectPath
      * @param projectPath
      * @param rootDirName
      * @param rootDirName
+     * @param executor
      */
      */
-    void execFile(String fileName, String projectPath, String rootDirName) throws IOException, InterruptedException;
+    void execFile(String fileName, String projectPath, String rootDirName, ExecutorService executor) throws IOException, InterruptedException;
 }
 }

+ 24 - 14
src/main/java/com/qmth/cet/plug/service/impl/LogicServiceImpl.java

@@ -15,6 +15,7 @@ import javax.annotation.Resource;
 import java.io.*;
 import java.io.*;
 import java.nio.charset.StandardCharsets;
 import java.nio.charset.StandardCharsets;
 import java.util.*;
 import java.util.*;
+import java.util.concurrent.ExecutorService;
 
 
 /**
 /**
  * @Description: logic service impl
  * @Description: logic service impl
@@ -36,9 +37,10 @@ public class LogicServiceImpl implements LogicService {
      * @param fileName
      * @param fileName
      * @param projectPath
      * @param projectPath
      * @param rootDirName
      * @param rootDirName
+     * @param executor
      */
      */
     @Override
     @Override
-    public void execFile(String fileName, String projectPath, String rootDirName) throws IOException, InterruptedException {
+    public void execFile(String fileName, String projectPath, String rootDirName, ExecutorService executor) throws IOException, InterruptedException {
         File mkdir = new File(fileName);
         File mkdir = new File(fileName);
         if (!mkdir.exists()) {
         if (!mkdir.exists()) {
             throw ExceptionResultEnum.ERROR.exception(rootDirName + "目录不存在");
             throw ExceptionResultEnum.ERROR.exception(rootDirName + "目录不存在");
@@ -61,21 +63,29 @@ public class LogicServiceImpl implements LogicService {
                     log.info("root:{}", root);
                     log.info("root:{}", root);
 
 
                     String lockKey = rootPath;
                     String lockKey = rootPath;
-                    for (; ; ) {
-                        boolean scanLock = lockService.lock(lockKey, lockKey, SystemConstant.LOCK_TIME_OUT);//30分钟
-                        if (scanLock) {
-                            try {
-                                this.scanTxtExecLogic(projectPath, rootPath, file);//扫描txt处理
-                            } catch (Exception e) {
-                                log.error(SystemConstant.LOG_ERROR, e);
-                            } finally {
-                                lockService.unlock(lockKey, lockKey);
-                                break;
+                    String finalRootPath = rootPath;
+                    executor.submit(() -> {
+                        log.info("启动新线程===>id:{},name:{}", Thread.currentThread().getId(), Thread.currentThread().getName());
+                        for (; ; ) {
+                            boolean scanLock = lockService.lock(lockKey, lockKey, SystemConstant.LOCK_TIME_OUT);//30分钟
+                            if (scanLock) {
+                                try {
+                                    this.scanTxtExecLogic(projectPath, finalRootPath, file);//扫描txt处理
+                                } catch (Exception e) {
+                                    log.error(SystemConstant.LOG_ERROR, e);
+                                } finally {
+                                    lockService.unlock(lockKey, lockKey);
+                                    break;
+                                }
+                            } else {
+                                try {
+                                    Thread.sleep(5000);
+                                } catch (InterruptedException e) {
+                                    log.error(SystemConstant.LOG_ERROR, e);
+                                }
                             }
                             }
-                        } else {
-                            Thread.sleep(5000);
                         }
                         }
-                    }
+                    });
                 }
                 }
             }
             }
         }
         }

+ 1 - 1
src/main/resources/application.properties

@@ -31,6 +31,6 @@ spring.jackson.time-zone=GMT+8
 com.qmth.logging.root-level=info
 com.qmth.logging.root-level=info
 com.qmth.logging.file-path=/Users/king/Downloads/cet-plug.log
 com.qmth.logging.file-path=/Users/king/Downloads/cet-plug.log
 
 
-com.qmth.client.dir=
+com.qmth.client.dir=/Users/king/Downloads
 com.qmth.cet4.dir=/Users/king/Downloads/cet4
 com.qmth.cet4.dir=/Users/king/Downloads/cet4
 com.qmth.cet6.dir=/Users/king/Downloads/cet6
 com.qmth.cet6.dir=/Users/king/Downloads/cet6