scala withDegreeOfParallelism

时间:2016-08-03 12:25:36

标签: scala parallel-processing

拥有.NET背景我试图为这里的并行集合实现一些“扩展方法”:

  implicit class ParSeqExtensions[T](pc : ParSeq[T]) {
    /** limits the number of threads of parallel collection - the equivalent of C# DegreeOfParallelizm*/
    def withDegreeOfParallelism(numberOfThreads: Int): ParSeq[T] = {
      pc.tasksupport = new ForkJoinTaskSupport(new scala.concurrent.forkjoin.ForkJoinPool(numberOfThreads))
      pc
    }
  }
  implicit class ParMapExtensions[K,V](map: ParMap[K,V]) {
    def withDegreeOfParallelism(numberOfThreads: Int): ParMap[K,V] = {
      map.tasksupport = new ForkJoinTaskSupport(new scala.concurrent.forkjoin.ForkJoinPool(numberOfThreads))
      map
    }
  }

taskSupport在特质中定义:

ParIterableLike[+Long, +Beginner <: Unreadable[TypeParameters]]

对于每个ParXyz集合类型分别实现相同的操作很无聊。斯卡拉是如此强大,一次成功吗?怎么样?

0 个答案:

没有答案