Skip to content

Commit 1c6a0cf

Browse files
committed
Merge pull request scala#2424 from rjolly/si-7399
SI-7399 : Take scala.concurrent.context.maxThreads into account
2 parents b88801f + e230409 commit 1c6a0cf

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/library/scala/concurrent/impl/ExecutionContextImpl.scala

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,19 @@ private[scala] class ExecutionContextImpl private[impl] (es: Executor, reporter:
5757

5858
def createExecutorService: ExecutorService = {
5959

60-
def getInt(name: String, f: String => Int): Int =
61-
try f(System.getProperty(name)) catch { case e: Exception => Runtime.getRuntime.availableProcessors }
62-
def range(floor: Int, desired: Int, ceiling: Int): Int =
63-
if (ceiling < floor) range(ceiling, desired, floor) else scala.math.min(scala.math.max(desired, floor), ceiling)
60+
def getInt(name: String, default: String) = (try System.getProperty(name, default) catch {
61+
case e: SecurityException => default
62+
}) match {
63+
case s if s.charAt(0) == 'x' => (Runtime.getRuntime.availableProcessors * s.substring(1).toDouble).ceil.toInt
64+
case other => other.toInt
65+
}
66+
67+
def range(floor: Int, desired: Int, ceiling: Int) = scala.math.min(scala.math.max(floor, desired), ceiling)
6468

6569
val desiredParallelism = range(
66-
getInt("scala.concurrent.context.minThreads", _.toInt),
67-
getInt("scala.concurrent.context.numThreads", {
68-
case null | "" => Runtime.getRuntime.availableProcessors
69-
case s if s.charAt(0) == 'x' => (Runtime.getRuntime.availableProcessors * s.substring(1).toDouble).ceil.toInt
70-
case other => other.toInt
71-
}),
72-
getInt("scala.concurrent.context.maxThreads", _.toInt))
70+
getInt("scala.concurrent.context.minThreads", "1"),
71+
getInt("scala.concurrent.context.numThreads", "x1"),
72+
getInt("scala.concurrent.context.maxThreads", "x1"))
7373

7474
val threadFactory = new DefaultThreadFactory(daemonic = true)
7575

0 commit comments

Comments
 (0)