|
@@ -27,6 +27,9 @@ import org.springframework.util.CollectionUtils;
|
|
|
import javax.annotation.Resource;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.CountDownLatch;
|
|
|
+import java.util.concurrent.ExecutorService;
|
|
|
+import java.util.concurrent.Executors;
|
|
|
|
|
|
/**
|
|
|
* 在线考试Service业务层处理
|
|
@@ -222,11 +225,7 @@ public class TElPaperServiceImpl implements ITElPaperService {
|
|
|
paper.setLimitTime(cl.getTime());
|
|
|
tElPaperMapper.insertTElPaper(paper);
|
|
|
// 保存试卷试题列表
|
|
|
- new Thread(() -> {
|
|
|
- this.savePaperQu(paper.getPaperId(), paperQuList);
|
|
|
- },"保存试卷试题列表").start();
|
|
|
-
|
|
|
-
|
|
|
+ this.savePaperQu(paper.getPaperId(), paperQuList);
|
|
|
|
|
|
String jobName = "break_exam_" + tElPaper.getPaperId();
|
|
|
// jobService.addCronJob(BreakExamJob.class, jobName, this.dateToCron(tElPaper.getLimitTime()),String.valueOf(tElPaper.getPaperId()));
|
|
@@ -482,6 +481,7 @@ public class TElPaperServiceImpl implements ITElPaperService {
|
|
|
List<TElPaperQuAnswer> batchAnswerList = new ArrayList<>();
|
|
|
long sort = 0;
|
|
|
TElQuAnswer qury = new TElQuAnswer();
|
|
|
+
|
|
|
for (TElPaperQu item : quList) {
|
|
|
item.setPaperId(paperId);
|
|
|
item.setSort(sort);
|
|
@@ -509,16 +509,49 @@ public class TElPaperServiceImpl implements ITElPaperService {
|
|
|
sort++;
|
|
|
}
|
|
|
//添加问题
|
|
|
+ //线程池
|
|
|
+ ExecutorService executorService = Executors.newFixedThreadPool(30);
|
|
|
+ final CountDownLatch latch = new CountDownLatch(quList.size()); //相同线程数量的计数
|
|
|
+
|
|
|
for (TElPaperQu q : batchQuList
|
|
|
) {
|
|
|
- tElPaperQuMapper.insertTElPaperQu(q);
|
|
|
+ executorService.execute(() -> {
|
|
|
+ try {
|
|
|
+ tElPaperQuMapper.insertTElPaperQu(q);
|
|
|
+ }finally {
|
|
|
+ latch.countDown(); //线程计数
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
+ try {
|
|
|
+ latch.await(); //线程计数完毕后继续执行
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ executorService.shutdown();
|
|
|
+
|
|
|
|
|
|
//批量添加问题答案
|
|
|
+ //线程池
|
|
|
+ ExecutorService executorService2 = Executors.newFixedThreadPool(30);
|
|
|
+ final CountDownLatch latch2 = new CountDownLatch(batchAnswerList.size()); //相同线程数量的计数
|
|
|
for (TElPaperQuAnswer answer : batchAnswerList
|
|
|
) {
|
|
|
- tElPaperQuAnswerMapper.insertTElPaperQuAnswer(answer);
|
|
|
+ executorService2.execute(() -> {
|
|
|
+ try {
|
|
|
+ tElPaperQuAnswerMapper.insertTElPaperQuAnswer(answer);
|
|
|
+ }finally {
|
|
|
+ latch2.countDown(); //线程计数
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
+ try {
|
|
|
+ latch2.await(); //线程计数完毕后继续执行
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ executorService2.shutdown();
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|