Starting from Scala 2.10, the preferred way to set the parallelism level is through setting the tasksupport field to a new TaskSupport object, as in the following example:scala> import scala.collection.parallel._import scala.collection.parallel._scala> val pc = mutable.ParArray(1, 2, 3)pc: scala.collection.parallel.mutable.ParArray[Int] = ParArray(1, 2, 3)scala> pc.tasksupport = new ForkJoinTaskSupport(new scala.concurrent.forkjoin.ForkJoinPool(2))pc.tasksupport: scala.collection.parallel.TaskSupport = scala.collection.parallel.ForkJoinTaskSupport@4a5d484ascala> pc map { _ + 1 }res0: scala.collection.parallel.mutable.ParArray[Int] = ParArray(2, 3, 4)在使用 fork 连接池实例化 ForkJoinTaskSupport 对象时,必须将 fork 连接池的并行级别设置为所需的值(示例中为 2).While instantiating the ForkJoinTaskSupport object with a fork join pool, the parallelism level of the fork join pool must be set to the desired value (2 in the example). 这篇关于scala 并行集合并行度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 1403页,肝出来的.. 09-06 22:28