0

I'd like to do something like this:

(1 to 100).parallel(20).filter(_ > 20).foreach(sendViaHttp)
List(1,3,5,9,100).parallel(3).map(fetchFromDatabase)

This means, "take a collection, create a thread pool with N threads, and run filter etc in that thread pool". My understanding of 2.8 collections (and scala in general) is sketchy. I've fiddled with CanBuildFrom, but I'm pretty certain either what I'm doing is wrong, or is just a bad idea.

Can someone help with some examples or pointers?

  • Do you have strong restriction on 2.8? 2.9 has [build-in](http://nikolajlindberg.blogspot.com/2011/04/testing-scala-290-rc2-parallel.html) parallel collections. – om-nom-nom Sep 07 '11 at 21:22
  • Even if I could switch to 2.9, I still need control of the level of parallelism. Does 2.9 support that? – Itai Zukerman Sep 07 '11 at 21:30
  • 3
    Yes, see here: http://stackoverflow.com/questions/5424496/scala-parallel-collections-degree-of-parallelism/5425354 – axel22 Sep 08 '11 at 01:45

1 Answers1

0

Aggregating the comments to an acceptable answer:

If you can switch to Scala 2.9 which has build-in parallel collections

If you want to control the amount of parallel threads you can do so using the advice here.

Community
  • 1
  • 1
Jens Schauder
  • 77,657
  • 34
  • 181
  • 348