summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaphael Jolly <rjolly@users.sourceforge.net>2013-04-21 12:20:40 +0200
committerRaphael Jolly <rjolly@users.sourceforge.net>2013-05-29 08:31:32 +0200
commite230409c13de167b0f4010464c74328ff91d9043 (patch)
tree83f5a56f443c1b5efdc9df771861a11a4a2e603b
parent01dec25425cefb6acc147d8341893eb70ca76245 (diff)
downloadscala-e230409c13de167b0f4010464c74328ff91d9043.tar.gz
scala-e230409c13de167b0f4010464c74328ff91d9043.tar.bz2
scala-e230409c13de167b0f4010464c74328ff91d9043.zip
SI-7399 : Take scala.concurrent.context.maxThreads into account
This change fixes the bug whereby specifiying maxThread as a property has no effect. A small refactoring is applied in the process.
-rw-r--r--src/library/scala/concurrent/impl/ExecutionContextImpl.scala22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/library/scala/concurrent/impl/ExecutionContextImpl.scala b/src/library/scala/concurrent/impl/ExecutionContextImpl.scala
index ed04293e0d..479720287c 100644
--- a/src/library/scala/concurrent/impl/ExecutionContextImpl.scala
+++ b/src/library/scala/concurrent/impl/ExecutionContextImpl.scala
@@ -57,19 +57,19 @@ private[scala] class ExecutionContextImpl private[impl] (es: Executor, reporter:
def createExecutorService: ExecutorService = {
- 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)
+ def getInt(name: String, default: String) = (try System.getProperty(name, default) catch {
+ case e: SecurityException => default
+ }) match {
+ case s if s.charAt(0) == 'x' => (Runtime.getRuntime.availableProcessors * s.substring(1).toDouble).ceil.toInt
+ case other => other.toInt
+ }
+
+ def range(floor: Int, desired: Int, ceiling: Int) = scala.math.min(scala.math.max(floor, desired), ceiling)
val desiredParallelism = range(
- getInt("scala.concurrent.context.minThreads", _.toInt),
- getInt("scala.concurrent.context.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.context.maxThreads", _.toInt))
+ getInt("scala.concurrent.context.minThreads", "1"),
+ getInt("scala.concurrent.context.numThreads", "x1"),
+ getInt("scala.concurrent.context.maxThreads", "x1"))
val threadFactory = new DefaultThreadFactory(daemonic = true)