for (Vertex ex: exitNodes){
LinkedList<Vertex> longPath = this.getLongestPathBL(task, ex);
if (longPath != null){
flag = true;
long temp = Level(longPath);
if (temp > maxLevel) {
maxLevel = temp;
}
}
}
我想并行执行以上代码,我尝试使用下面的代码,但ex是一个列表,而不是整数,我知道如何解决它吗?
int a= vertexes.size();
IntStream.range(0, a).parallel().forEach(i->{
// for (Vertex ex: exitNodes){
LinkedList<Vertex> longPath = this.getLongestPathBL(task, ex);
if (longPath != null){
flag = true;
long temp = Level(longPath);
if (temp > maxLevel) {
maxLevel = temp;
}
}
});
你可以做
Alternatively you can replace
forEach
loop with map-filter-reduce, e.g.备注:
level
instead ofLevel