|
@@ -38,6 +38,10 @@ import java.util.ArrayList;
|
|
|
import java.util.LinkedHashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.concurrent.Callable;
|
|
|
+import java.util.concurrent.ExecutorService;
|
|
|
+import java.util.concurrent.Executors;
|
|
|
+import java.util.concurrent.Future;
|
|
|
|
|
|
/**
|
|
|
* @Description: 测试facade
|
|
@@ -320,7 +324,7 @@ public class TestFacade {
|
|
|
continue;
|
|
|
}
|
|
|
// 3,4是高危手术
|
|
|
- if ("0".equals(bean.getOperationLevel()) || "1".equals(bean.getOperationLevel()) || "2".equals(bean.getOperationLevel())) {
|
|
|
+ if (StringUtil.isBlank(bean.getOperationLevel()) || "0".equals(bean.getOperationLevel()) || "1".equals(bean.getOperationLevel()) || "2".equals(bean.getOperationLevel())) {
|
|
|
continue;
|
|
|
}
|
|
|
IndicationPushVO indicationPushVO = new IndicationPushVO();
|
|
@@ -899,7 +903,44 @@ public class TestFacade {
|
|
|
// indicationPushVOList.add(indicationPushVO);
|
|
|
}
|
|
|
|
|
|
- Map<String, Object> map = getDebugMap(indicationPushVOList, "3", start);
|
|
|
+ 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());
|
|
|
+ }
|
|
|
return map;
|
|
|
}
|
|
|
|
|
@@ -1041,4 +1082,27 @@ public class TestFacade {
|
|
|
public int getRandomNum(int size) {
|
|
|
return (int)(Math.random() * size);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 将列表按列表总长度划分
|
|
|
+ *
|
|
|
+ * @param originList 数据
|
|
|
+ * @param num 份数
|
|
|
+ * @param <T>
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public <T> List<List<T>> divideByCopies(List<T> originList, int num) {
|
|
|
+ List<List<T>> list = new ArrayList<>();
|
|
|
+ if (ListUtil.isEmpty(originList) || num < 0) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ for (int i = 0; i < num; i++) {
|
|
|
+ list.add(new ArrayList<T>());
|
|
|
+ }
|
|
|
+ for (int i = 0; i < originList.size(); i++) {
|
|
|
+ list.get(i % num).add(originList.get(i));
|
|
|
+ }
|
|
|
+
|
|
|
+ return list;
|
|
|
+ }
|
|
|
}
|