ParallelStreams多线程执行设置线程池数量


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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM