// 串行執行流 stream().filter(e -> e > 10).count(); // 並行執行流 parallelStream().filter(e -> e > 10).count()
ParallelStreams 默認使用 ForkJoinPool.commonPool()線程池。
roster.parallelStream().reduce(0, Integer::sum)
修改線程池大小
ForkJoinPool customThreadPool = new ForkJoinPool(4); long actualTotal = customThreadPool.submit(() -> roster.parallelStream().reduce(0, Integer::sum)).get();