From 34b90d24842d1b5d7bfb4f42d9f123d9766acbe4 Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Wed, 1 Dec 2021 15:32:06 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E5=B9=B6=E5=8F=91=E6=8A=A5=E5=91=8A=E5=AD=98=E5=82=A8=E5=A4=84?= =?UTF-8?q?=E7=90=86=EF=BC=8C=E6=89=A7=E8=A1=8C=E5=89=8D=E4=BC=98=E5=85=88?= =?UTF-8?q?=E6=8F=90=E4=BA=A4=E5=85=A5=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/service/ApiAutomationService.java | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java index 9e9607351d..ada6f363b4 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java @@ -1440,16 +1440,23 @@ public class ApiAutomationService { * @param request */ private void parallel(Map executeQueue, RunScenarioRequest request) { - SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH); - ApiScenarioReportMapper batchMapper = sqlSession.getMapper(ApiScenarioReportMapper.class); - // 开始并发执行 - for (String reportId : executeQueue.keySet()) { - //存储报告 - APIScenarioReportResult report = executeQueue.get(reportId).getReport(); - batchMapper.insert(report); - MessageCache.scenarioExecResourceLock.put(reportId, report); - } - sqlSession.flushStatements(); + Thread thread = new Thread(new Runnable() { + @Override + public void run() { + SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH); + ApiScenarioReportMapper batchMapper = sqlSession.getMapper(ApiScenarioReportMapper.class); + // 开始并发执行 + for (String reportId : executeQueue.keySet()) { + //存储报告 + APIScenarioReportResult report = executeQueue.get(reportId).getReport(); + batchMapper.insert(report); + MessageCache.scenarioExecResourceLock.put(reportId, report); + } + sqlSession.commit(); + sqlSession.clearCache(); + } + }); + thread.start(); for (String reportId : executeQueue.keySet()) { // 增加一个本地锁,防止并发找不到资源