summaryrefslogtreecommitdiff
path: root/src/library/scala/concurrent/impl
diff options
context:
space:
mode:
authorSimon Ochsenreither <simon@ochsenreither.de>2015-10-27 23:40:17 +0100
committerSimon Ochsenreither <simon@ochsenreither.de>2015-10-28 16:26:40 +0100
commiteb4f33d71ad2053187739b96a2f40cd70ba5ee1e (patch)
tree7ddf29ed199b2076813177ae8c9f53dae43f5c5b /src/library/scala/concurrent/impl
parent4321ea458ad1258f273ee22a4c6a7606ab054501 (diff)
downloadscala-eb4f33d71ad2053187739b96a2f40cd70ba5ee1e.tar.gz
scala-eb4f33d71ad2053187739b96a2f40cd70ba5ee1e.tar.bz2
scala-eb4f33d71ad2053187739b96a2f40cd70ba5ee1e.zip
Remove ThreadPoolExecutor fallback in ExecutionContextImpl
The method createDefaultExecutorService had a fallback if the creation of a ForkJoinPool didn't succeed. This was necessary, because Scala shipped its own version of FJP, and the dependency on sun.misc.Unsafe (which is not an "offical" official API) made portability slightly questionable. Now that we can assume that FJP is supplied by the JDK, this concern goes away.
Diffstat (limited to 'src/library/scala/concurrent/impl')
-rw-r--r--src/library/scala/concurrent/impl/ExecutionContextImpl.scala43
1 files changed, 12 insertions, 31 deletions
diff --git a/src/library/scala/concurrent/impl/ExecutionContextImpl.scala b/src/library/scala/concurrent/impl/ExecutionContextImpl.scala
index c98746a98d..4cb5f51e62 100644
--- a/src/library/scala/concurrent/impl/ExecutionContextImpl.scala
+++ b/src/library/scala/concurrent/impl/ExecutionContextImpl.scala
@@ -8,13 +8,10 @@
package scala.concurrent.impl
-
-
-import java.util.concurrent.{ ForkJoinPool, ForkJoinWorkerThread, ForkJoinTask, LinkedBlockingQueue, Callable, Executor, ExecutorService, Executors, ThreadFactory, TimeUnit, ThreadPoolExecutor }
+import java.util.concurrent.{ ForkJoinPool, ForkJoinWorkerThread, ForkJoinTask, Callable, Executor, ExecutorService, Executors, ThreadFactory, TimeUnit }
import java.util.concurrent.atomic.AtomicInteger
import java.util.Collection
import scala.concurrent.{ BlockContext, ExecutionContext, Awaitable, CanAwait, ExecutionContextExecutor, ExecutionContextExecutorService }
-import scala.util.control.NonFatal
import scala.annotation.tailrec
@@ -57,7 +54,7 @@ private[concurrent] object ExecutionContextImpl {
}
// As per ThreadFactory contract newThread should return `null` if cannot create new thread.
- def newThread(runnable: Runnable): Thread =
+ def newThread(runnable: Runnable): Thread =
if (reserveThread())
wire(new Thread(new Runnable {
// We have to decrement the current thread count when the thread exits
@@ -80,7 +77,7 @@ private[concurrent] object ExecutionContextImpl {
} finally {
isdone = true
}
-
+
true
}
override def isReleasable = isdone
@@ -123,33 +120,17 @@ private[concurrent] object ExecutionContextImpl {
prefix = "scala-execution-context-global",
uncaught = uncaughtExceptionHandler)
- try {
- new ForkJoinPool(desiredParallelism, threadFactory, uncaughtExceptionHandler, true) {
- override def execute(runnable: Runnable): Unit = {
- val fjt: ForkJoinTask[_] = runnable match {
- case t: ForkJoinTask[_] => t
- case r => new ExecutionContextImpl.AdaptedForkJoinTask(r)
- }
- Thread.currentThread match {
- case fjw: ForkJoinWorkerThread if fjw.getPool eq this => fjt.fork()
- case _ => super.execute(fjt)
- }
+ new ForkJoinPool(desiredParallelism, threadFactory, uncaughtExceptionHandler, true) {
+ override def execute(runnable: Runnable): Unit = {
+ val fjt: ForkJoinTask[_] = runnable match {
+ case t: ForkJoinTask[_] => t
+ case r => new ExecutionContextImpl.AdaptedForkJoinTask(r)
+ }
+ Thread.currentThread match {
+ case fjw: ForkJoinWorkerThread if fjw.getPool eq this => fjt.fork()
+ case _ => super.execute(fjt)
}
}
- } catch {
- case NonFatal(t) =>
- System.err.println("Failed to create ForkJoinPool for the default ExecutionContext, falling back to ThreadPoolExecutor")
- t.printStackTrace(System.err)
- val exec = new ThreadPoolExecutor(
- desiredParallelism,
- desiredParallelism,
- 5L,
- TimeUnit.MINUTES,
- new LinkedBlockingQueue[Runnable],
- threadFactory
- )
- exec.allowCoreThreadTimeOut(true)
- exec
}
}