@@ -101,20 +101,26 @@ private[concurrent] object ExecutionContextImpl {
101
101
}
102
102
103
103
def range (floor : Int , desired : Int , ceiling : Int ) = scala.math.min(scala.math.max(floor, desired), ceiling)
104
-
104
+ val numThreads = getInt(" scala.concurrent.context.numThreads" , " x1" )
105
+ // The hard limit on the number of active threads that the thread factory will produce
106
+ // SI-8955 Deadlocks can happen if maxNoOfThreads is too low, although we're currently not sure
107
+ // about what the exact threshhold is. numThreads + 256 is conservatively high.
105
108
val maxNoOfThreads = getInt(" scala.concurrent.context.maxThreads" , " x1" )
106
109
107
110
val desiredParallelism = range(
108
111
getInt(" scala.concurrent.context.minThreads" , " 1" ),
109
- getInt( " scala.concurrent.context. numThreads" , " x1 " ) ,
112
+ numThreads,
110
113
maxNoOfThreads)
111
114
115
+ // The thread factory must provide additional threads to support managed blocking.
116
+ val maxExtraThreads = getInt(" scala.concurrent.context.maxExtraThreads" , " 256" )
117
+
112
118
val uncaughtExceptionHandler : Thread .UncaughtExceptionHandler = new Thread .UncaughtExceptionHandler {
113
119
override def uncaughtException (thread : Thread , cause : Throwable ): Unit = reporter(cause)
114
120
}
115
121
116
122
val threadFactory = new ExecutionContextImpl .DefaultThreadFactory (daemonic = true ,
117
- maxThreads = maxNoOfThreads,
123
+ maxThreads = maxNoOfThreads + maxExtraThreads ,
118
124
prefix = " scala-execution-context-global" ,
119
125
uncaught = uncaughtExceptionHandler)
120
126
0 commit comments