From 2f8921fd26cf25bdbc4901b02e5f57c00eda3d8c Mon Sep 17 00:00:00 2001 From: youys <1272586223@qq.com> Date: Thu, 20 Jan 2022 15:09:48 +0800 Subject: [PATCH] adjust --- .../educoder/ecsonar/config/ThreadPoolConfig.java | 4 ++-- .../net/educoder/ecsonar/services/SonarService.java | 12 ++++++++---- .../ecsonar/task/SonarQueryResultRunnable.java | 5 ++--- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/main/java/net/educoder/ecsonar/config/ThreadPoolConfig.java b/src/main/java/net/educoder/ecsonar/config/ThreadPoolConfig.java index 1c91efe..75d4e1d 100644 --- a/src/main/java/net/educoder/ecsonar/config/ThreadPoolConfig.java +++ b/src/main/java/net/educoder/ecsonar/config/ThreadPoolConfig.java @@ -14,7 +14,7 @@ public class ThreadPoolConfig { @Primary public ExecutorService sonarScannerPool() { ThreadFactory sonarScannerPool = new CustomizableThreadFactory("sonarScanner-pool-"); - return new ThreadPoolExecutor(20, 20, 0, + return new ThreadPoolExecutor(10, 10, 0, TimeUnit.SECONDS, new ArrayBlockingQueue<>(10000), sonarScannerPool, new ThreadPoolExecutor.AbortPolicy()); } @@ -23,7 +23,7 @@ public class ThreadPoolConfig { @Bean("sonarQueryResultPool") public ExecutorService queryResultPool() { ThreadFactory sonarQueryResultPool = new CustomizableThreadFactory("sonarQueryResult-pool-"); - return new ThreadPoolExecutor(10, 10, 0, + return new ThreadPoolExecutor(5, 5, 0, TimeUnit.SECONDS, new ArrayBlockingQueue<>(10000), sonarQueryResultPool, new ThreadPoolExecutor.AbortPolicy()); diff --git a/src/main/java/net/educoder/ecsonar/services/SonarService.java b/src/main/java/net/educoder/ecsonar/services/SonarService.java index 4fadce7..d135495 100644 --- a/src/main/java/net/educoder/ecsonar/services/SonarService.java +++ b/src/main/java/net/educoder/ecsonar/services/SonarService.java @@ -63,7 +63,9 @@ public class SonarService { "-Dsonar.java.binaries=./ " + "-Dsonar.projectBaseDir=" + param.getProjectPath(); - SystemUtil.executeAndGetExitStatus(command); + SystemUtil.ExecuteResp executeResp = SystemUtil.executeAndGetExitStatus(command); + log.info("java语言:command{},result:{}",command,executeResp.getOutput()); + }); concurrentHashMap.put(Constant.PYTHON, param -> { String command = "sonar-scanner " + @@ -72,7 +74,8 @@ public class SonarService { "-Dsonar.projectKey=" + param.getProjectKey() + " " + "-Dsonar.projectBaseDir=" + param.getProjectPath(); - SystemUtil.executeAndGetExitStatus(command); + SystemUtil.ExecuteResp executeResp = SystemUtil.executeAndGetExitStatus(command); + log.info("python语言:command{},result:{}",command,executeResp.getOutput()); }); concurrentHashMap.put(Constant.C, param -> { String command = "cppcheck --xml --xml-version=2 --enable=all " + param.getProjectPath() + " 2> " + param.getCppCheckReportPath() + @@ -82,7 +85,8 @@ public class SonarService { "-Dsonar.projectKey=" + param.getProjectKey() + " " + "-Dsonar.cxx.cppcheck.reportPath=" + param.getCppCheckReportPath() + " " + "-Dsonar.projectBaseDir=" + param.getProjectPath(); - SystemUtil.executeAndGetExitStatus(command); + SystemUtil.ExecuteResp executeResp = SystemUtil.executeAndGetExitStatus(command); + log.info("c语言:command{},result:{}",command,executeResp.getOutput()); }); concurrentHashMap.put(Constant.CXX, param -> { String command = "cppcheck --xml --xml-version=2 --enable=all " + param.getProjectPath() + " 2> " + param.getCppCheckReportPath() + @@ -93,7 +97,7 @@ public class SonarService { "-Dsonar.cxx.cppcheck.reportPath=" + param.getCppCheckReportPath() + " " + "-Dsonar.projectBaseDir=" + param.getProjectPath(); SystemUtil.ExecuteResp executeResp = SystemUtil.executeAndGetExitStatus(command); - log.info("command:{}, result:{}", command, executeResp.getOutput()); + log.info("c++: command:{}, result:{}", command, executeResp.getOutput()); }); } diff --git a/src/main/java/net/educoder/ecsonar/task/SonarQueryResultRunnable.java b/src/main/java/net/educoder/ecsonar/task/SonarQueryResultRunnable.java index 4143ecf..e22a247 100644 --- a/src/main/java/net/educoder/ecsonar/task/SonarQueryResultRunnable.java +++ b/src/main/java/net/educoder/ecsonar/task/SonarQueryResultRunnable.java @@ -1,7 +1,6 @@ package net.educoder.ecsonar.task; import net.educoder.ecsonar.services.DbOperateService; -import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -31,10 +30,10 @@ public class SonarQueryResultRunnable implements Runnable { int count = 0; String status; - while((status = dbOperateService.queryCeActivityStatus(projectName)) == null && count++ <=120){ + while((status = dbOperateService.queryCeActivityStatus(projectName)) == null && count++ <= 60){ LOGGER.info("detailId:[{}],sonar还未执行完,次数:{}", detailId, count); try { - Thread.sleep(1000); + Thread.sleep(2000); } catch (InterruptedException e) {} } // 查询