|
@@ -239,7 +239,8 @@ public class TestFacade {
|
|
|
indicationPushVOList.add(indicationPushVO);
|
|
|
}
|
|
|
|
|
|
- Map<String, Object> map = getDebugMap(indicationPushVOList, "2", start);
|
|
|
+ // Map<String, Object> map = getDebugMap(indicationPushVOList, "2", start);
|
|
|
+ Map<String, Object> map = getDebugMapMulti(indicationPushVOList, "2", start);
|
|
|
return map;
|
|
|
}
|
|
|
|
|
@@ -903,44 +904,7 @@ public class TestFacade {
|
|
|
// indicationPushVOList.add(indicationPushVO);
|
|
|
}
|
|
|
|
|
|
- Map<String, Object> map = new LinkedHashMap<>();
|
|
|
- map.put("总条数", indicationPushVOList.size() + "条");
|
|
|
-
|
|
|
- List<String> errMsg = new ArrayList<>();
|
|
|
- try {
|
|
|
- int threadNum = 8; // 推荐的总线程数 = cpu个数 * 每个cpu的核数
|
|
|
- List<List<IndicationPushVO>> threadData = divideByCopies(indicationPushVOList, threadNum);
|
|
|
- List<Future<Map>> list = new ArrayList<>();
|
|
|
-
|
|
|
- ExecutorService executor = Executors.newFixedThreadPool(threadNum);
|
|
|
- for (int i = 0; i < threadNum; i++) {
|
|
|
- final int index = i; // 这一行代码很重要,如果使用成员变量,下面会报错
|
|
|
- Future<Map> future = executor.submit(new Callable<Map>() {
|
|
|
- @Override
|
|
|
- public Map call() {
|
|
|
- List<IndicationPushVO> data = threadData.get(index);
|
|
|
- return getDebugMap(data, "3", start);
|
|
|
- }
|
|
|
- });
|
|
|
- list.add(future);
|
|
|
- }
|
|
|
-
|
|
|
- // 拼接返回数据
|
|
|
- for (int i = 0; i < list.size(); i++) {
|
|
|
- Future<Map> future = list.get(i);
|
|
|
- while(!future.isDone()); // 这一行代码很重要
|
|
|
- List<String> obj = (List<String>)future.get().get("出错信息");
|
|
|
- if (ListUtil.isNotEmpty(obj)) {
|
|
|
- errMsg.addAll(obj);
|
|
|
- }
|
|
|
- }
|
|
|
- map.put("出错信息", errMsg);
|
|
|
- map.put("出错条数", errMsg.size() + "条");
|
|
|
- Long t2 = System.currentTimeMillis();
|
|
|
- map.put("执行时间", (t2 - start) / 1000.0 + "秒");
|
|
|
- } catch (Exception e) {
|
|
|
- throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "多线程执行高风险手术复杂情况失败:" + e.getMessage());
|
|
|
- }
|
|
|
+ Map<String, Object> map = getDebugMapMulti(indicationPushVOList, "3", start);
|
|
|
return map;
|
|
|
}
|
|
|
|
|
@@ -999,6 +963,54 @@ public class TestFacade {
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 多线程执行
|
|
|
+ *
|
|
|
+ * @param indicationPushVOList
|
|
|
+ * @param start
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Map getDebugMapMulti(List<IndicationPushVO> indicationPushVOList, String ruleType, long start) {
|
|
|
+ Map<String, Object> map = new LinkedHashMap<>();
|
|
|
+ List<String> errMsg = new ArrayList<>();
|
|
|
+ try {
|
|
|
+ int threadNum = 8; // 推荐的总线程数 = cpu个数 * 每个cpu的核数
|
|
|
+ List<List<IndicationPushVO>> threadData = divideByCopies(indicationPushVOList, threadNum);
|
|
|
+ List<Future<Map>> list = new ArrayList<>();
|
|
|
+
|
|
|
+ ExecutorService executor = Executors.newFixedThreadPool(threadNum);
|
|
|
+ for (int i = 0; i < threadNum; i++) {
|
|
|
+ final int index = i; // 这一行代码很重要,如果使用成员变量,下面会报错
|
|
|
+ Future<Map> future = executor.submit(new Callable<Map>() {
|
|
|
+ @Override
|
|
|
+ public Map call() {
|
|
|
+ List<IndicationPushVO> data = threadData.get(index);
|
|
|
+ return getDebugMap(data, ruleType, start);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ list.add(future);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 拼接返回数据
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
+ Future<Map> future = list.get(i);
|
|
|
+ while(!future.isDone()); // 这一行代码很重要
|
|
|
+ List<String> obj = (List<String>)future.get().get("出错信息");
|
|
|
+ if (ListUtil.isNotEmpty(obj)) {
|
|
|
+ errMsg.addAll(obj);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ map.put("总条数", indicationPushVOList.size() + "条");
|
|
|
+ map.put("出错信息", errMsg);
|
|
|
+ map.put("出错条数", errMsg.size() + "条");
|
|
|
+ Long t2 = System.currentTimeMillis();
|
|
|
+ map.put("执行时间", (t2 - start) / 1000.0 + "秒");
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "多线程执行高风险手术复杂情况失败:" + e.getMessage());
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
public void setname(IndicationPushVO indicationPushVO, TestIndicationVO bean) {
|
|
|
List<Item> operationOrder = new ArrayList<>();
|
|
|
Item item = new Item();
|