# n组
public static <T> List<List<T>> averageAssign(List<T> source, int n) { List<List<T>> result = Lists.newArrayList(); int renumber = source.size() % n; int number = source.size() / n; int offset = 0; for (int i = 0; i < n; i++) { List<T> value; if (renumber > 0) { value = source.subList(i * number + offset, (i + 1) * number + offset + 1); renumber--; offset++; } else { value = source.subList(i * number + offset, (i + 1) * number + offset); } result.add(value); } return result; }
subLists = averageAssign(dtoList, 4);
List<CompletableFuture<Void>> cfList = new ArrayList<>(4);标签:int,List,list,number,subList,source,分组,拆分,offset From: https://www.cnblogs.com/yk775879106/p/17687374.html
for(List<Integer> subList: subLists) {
cfList.add(CompletableFuture.runAsync(() -> batchRun(null, subList, null)));
}
CompletableFuture.allOf(cfList.toArray(new CompletableFuture[0])).join();