// 串行执行流
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();

 

相关文章: