java arrayList结构很容易使用并行流处理 对于map 到是没有现成方式
今天遇到一个map 顺序执行需要降低耗时的 场景,想到了一种方法 供参考
// 新方法 map使用并行流 //使用entrySet 的key的list 然后当成list遍历
projectGitMap.entrySet().parallelStream().forEach(entry->{
List<Integer> list = projectGitMap.get(entry.getKey()); //entry.getKey() = name
list.parallelStream().forEach(projectId -> {
List<String> gitlabCommitIdList = getGitlabCommitId(begin, end, projectId);
gitlabCommitIdList.parallelStream().forEach(commitId -> {
calcChangeLine(entry.getKey(), projectId, commitId, gitlabChangeLineMap);
});
});
});
//old方式 map顺序执行 结构
projectGitMap.forEach((name, list) -> {
list.parallelStream().forEach(projectId -> {
List<String> gitlabCommitIdList = getGitlabCommitId(begin, end, projectId);
gitlabCommitIdList.parallelStream().forEach(commitId -> {
calcChangeLine(name, projectId, commitId, gitlabChangeLineMap);
});
});
});