多线程

String columnName = request.get("columnName").toString();
String fieldName = request.get("fieldName").toString();
fieldName = "".equals(fieldName.trim()) ? "CUS2-OFFICE-PHONE,CR-ACCT-NBR,CUS2-TEL-2,CM_ORG_NMBR" : fieldName;
List<Object> fieldList = new ArrayList<>();
Map<String, Object> resultMap = new HashMap<>();
if (fieldName != null && !"".equals(fieldName.trim())) {
String fieldName2 = fieldName.replaceAll("\"", "").replaceAll("'", "").replaceAll("\\[", "").replaceAll("]", "").replaceAll(",", "|")
.replaceAll(";", "|").replaceAll(" ", "|").replaceAll(",", "|").replaceAll("\\\n", "|").replaceAll("\\\t", "|")
.replaceAll("_", "-").replaceAll("\\|+", "|");
String[] fieldNames = fieldName2.split("\\|");
List<String> collect = Arrays.asList(fieldNames).stream().filter(s -> !"".equals(s)).collect(Collectors.toList());

CompletableFuture[] completableFutures = collect.stream().
map(t -> CompletableFuture
.supplyAsync(() -> getFields(t), executorService)
.whenCompleteAsync((result,throwable) -> {
fieldList.add(result);
},executorService)).toArray(CompletableFuture[]::new);

// 开始等待所有任务执行完成
CompletableFuture.allOf(completableFutures).join();


}

List<Object> resultList = new ArrayList<>();

for (int i = 0; i < fieldList.size(); i++) {
JSONArray o = (JSONArray)fieldList.get(i);
for (int i1 = 0; i1 < o.size(); i1++) {
if (o.get(i1) instanceof JSONObject)
resultList.add(o.get(i1));
}
}
posted @ 2021-07-06 19:58  送一轮明月  阅读(41)  评论(0)    收藏  举报