scala学习笔记:理解并行集合par
scala> (1 to 5).foreach(println(_))
1
2
3
4
5
scala> (1 to 5).par.foreach(println(_))
3
1
4
2
5
以下代码获取到参与并行计算的线程:
scala> (0 to 10000).collect{case _ => Thread.currentThread.getName}.distinct
res53: scala.collection.immutable.IndexedSeq[java.lang.String] = Vector(Thread-57)
scala> (0 to 10000).par.collect{case _ => Thread.currentThread.getName}.distinct
res54: scala.collection.parallel.immutable.ParSeq[java.lang.String] = ParVector(ForkJoinPool-1-worker-0, ForkJoinPool-1-worker-4, ForkJoinPool-1-worker-5, ForkJoinPool-1-worker-2, ForkJoinPool-1-worker-6, ForkJoinPool-1-worker-1, ForkJoinPool-1-worker-7)
+++++++++++++++++++++++++++++++++++++++++++
如本文存在任何侵权部分,请及时告知,我会第一时间删除!
转载本博客原创文章,请附上原文@cnblogs的网址!
QQ: 5854165 我的开源项目 欢迎大家一起交流编程架构技术&大数据技术! +++++++++++++++++++++++++++++++++++++++++++
如本文存在任何侵权部分,请及时告知,我会第一时间删除!
转载本博客原创文章,请附上原文@cnblogs的网址!
QQ: 5854165 我的开源项目 欢迎大家一起交流编程架构技术&大数据技术! +++++++++++++++++++++++++++++++++++++++++++