|
@@ -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);
|
|
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
+ });
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|