diff options
author | James Iry <jamesiry@gmail.com> | 2013-05-29 07:59:52 -0700 |
---|---|---|
committer | James Iry <jamesiry@gmail.com> | 2013-05-29 07:59:52 -0700 |
commit | 1c6a0cf75592c201e27a6e11140c6da87de67123 (patch) | |
tree | 0360b2c4509111de55a70f5e09a9782f4a878020 /src/library | |
parent | b88801fac7cb1d7d38d4b3cca4aab4603c48527e (diff) | |
parent | e230409c13de167b0f4010464c74328ff91d9043 (diff) | |
download | scala-1c6a0cf75592c201e27a6e11140c6da87de67123.tar.gz scala-1c6a0cf75592c201e27a6e11140c6da87de67123.tar.bz2 scala-1c6a0cf75592c201e27a6e11140c6da87de67123.zip |
Merge pull request #2424 from rjolly/si-7399
SI-7399 : Take scala.concurrent.context.maxThreads into account
Diffstat (limited to 'src/library')
-rw-r--r-- | src/library/scala/concurrent/impl/ExecutionContextImpl.scala | 22 |
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) |