summaryrefslogtreecommitdiff
path: root/src/library/scala/concurrent/impl
diff options
context:
space:
mode:
authorphaller <philipp.haller@typesafe.com>2012-06-05 12:08:32 +0200
committerphaller <philipp.haller@typesafe.com>2012-06-05 12:08:32 +0200
commite5f42a9b88e0a3ca1ac72e2c09ff3c954c3781ac (patch)
tree538a9a8d883a9a71249d8811f1016332e638681d /src/library/scala/concurrent/impl
parente90ea27cbeff305860a583160373a2af5b59581d (diff)
downloadscala-e5f42a9b88e0a3ca1ac72e2c09ff3c954c3781ac.tar.gz
scala-e5f42a9b88e0a3ca1ac72e2c09ff3c954c3781ac.tar.bz2
scala-e5f42a9b88e0a3ca1ac72e2c09ff3c954c3781ac.zip
Add configuration for ExecutionContext
Diffstat (limited to 'src/library/scala/concurrent/impl')
-rw-r--r--src/library/scala/concurrent/impl/ExecutionContextImpl.scala28
1 files changed, 21 insertions, 7 deletions
diff --git a/src/library/scala/concurrent/impl/ExecutionContextImpl.scala b/src/library/scala/concurrent/impl/ExecutionContextImpl.scala
index 1083a93439..7549bf8314 100644
--- a/src/library/scala/concurrent/impl/ExecutionContextImpl.scala
+++ b/src/library/scala/concurrent/impl/ExecutionContextImpl.scala
@@ -43,17 +43,31 @@ private[scala] class ExecutionContextImpl private[impl] (es: Executor, reporter:
}
}
}
-
- def createExecutorService: ExecutorService = try { new ForkJoinPool(
- Runtime.getRuntime.availableProcessors(), //FIXME from config
- forkJoinPoolThreadFactory,
- null, //FIXME we should have an UncaughtExceptionHandler, see what Akka does
- true) //FIXME I really think this should be async...
+
+ def createExecutorService: ExecutorService = try {
+ def getInt(name: String, f: String => Int): Int =
+ try f(System.getProperty(name)) catch { case e: Exception => Runtime.getRuntime.availableProcessors }
+ def range(floor: Int, desired: Int, ceiling: Int): Int =
+ if (ceiling < floor) range(ceiling, desired, floor) else scala.math.min(scala.math.max(desired, floor), ceiling)
+
+ new ForkJoinPool(
+ range(
+ getInt("scala.concurrent.ec.minThreads", _.toInt),
+ getInt("scala.concurrent.ec.numThreads", {
+ case null | "" => Runtime.getRuntime.availableProcessors
+ case s if s.charAt(0) == 'x' => (Runtime.getRuntime.availableProcessors * s.substring(1).toDouble).ceil.toInt
+ case other => other.toInt
+ }),
+ getInt("scala.concurrent.ec.maxThreads", _.toInt)
+ ),
+ forkJoinPoolThreadFactory,
+ null, //FIXME we should have an UncaughtExceptionHandler, see what Akka does
+ true) //FIXME I really think this should be async...
} catch {
case NonFatal(t) =>
System.err.println("Failed to create ForkJoinPool for the default ExecutionContext, falling back to Executors.newCachedThreadPool")
t.printStackTrace(System.err)
- Executors.newCachedThreadPool(executorsThreadFactory)
+ Executors.newCachedThreadPool(executorsThreadFactory) //FIXME use the same desired parallelism here too?
}
def execute(runnable: Runnable): Unit = executor match {