SHORT VERSION
I'm looking for a way to set once and for all what Pool to use globally when I call the .par function of a collection...
Up to now I found only how to set the number of threads in the global ExecutionContext but not how to change the actual Pool used by default.
I merely want to explicitly specify the ForkJoinPool to make the parallel collections ExecutionContext independent from the Scala version I use.
LONG VERSION This requirement came in after we've got issues because Scala 2.10 doesn't support JDK 1.8
Scala simply didn't recognize the java version and thought we were still in 1.5, hence the pool was a different type and the number of threads wasn't limited to the number of processors
The problem is caused by this code:
if (scala.util.Properties.isJavaAtLeast("1.6")) new ForkJoinTaskSupport
else new ThreadPoolTaskSupport
def isJavaAtLeast(version: String) = {
val okVersions = version match {
case "1.5" => List("1.5", "1.6", "1.7")
case "1.6" => List("1.6", "1.7")
case "1.7" => List("1.7")
case _ => Nil
}
okVersions exists (javaVersion startsWith _)
}
As how we manage threads is quite critical in our application and we don't want unexpected surprises just changing a version, I wondered if it was possible to force Scala to use ForkJoinPool with a preset number of threads decided by us GLOBALLY (I don't want the single instance solution described here Scala Parallel Collections: How to know and configure the number of threads)
hope it's clear enough!