(String[] args)
| 9 | |
| 10 | public class CountingStream { |
| 11 | public static void main(String[] args) { |
| 12 | System.out.println( |
| 13 | IntStream.range(0, 10) |
| 14 | .parallel() |
| 15 | .mapToObj(CountingTask::new) |
| 16 | .map(ct -> ct.call()) |
| 17 | .reduce(0, Integer::sum)); |
| 18 | } |
| 19 | } |
| 20 | /* Output: |
| 21 | 1 ForkJoinPool.commonPool-worker-3 100 |