Closed
Description
二十四章-并发编程
- 并行流模块
Java 8 流的一个显著优点是,在某些情况下,它们可以很容易地并行化。这来自仔细的库设计,
最后一句建议改为 这来自库的仔细设计 会更通顺一点
- 另在同模块的代码中 如下
// concurrent/ParallelStreamPuzzle.java
import java.util.*;
import java.util.function.*;
import java.util.stream.*;
public class ParallelStreamPuzzle {
static class IntGenerator
implements Supplier<Integer> {
private int current = 0;
@Override
public Integer get() {
return current++;
}
}
public static void main(String[] args) {
List<Integer> x = Stream.generate(newIntGenerator())
.limit(10)
.parallel() // [1]
.collect(Collectors.toList());
System.out.println(x);
}
}
List x = Stream.generate(newIntGenerator())应改为new IntGenerator()
Metadata
Metadata
Assignees
Labels
No labels