diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2015-11-13 13:50:25 +1000 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2015-11-13 13:50:25 +1000 |
commit | 5cb3d4ec14488ce2fc5a1cc8ebdd12845859c57d (patch) | |
tree | eaf1f83caa0797bfc5bc49ac2c56ed53054c29a2 /src/library | |
parent | a113bbec715ec9654cd82142be22eefd917f4f0e (diff) | |
parent | eb4f33d71ad2053187739b96a2f40cd70ba5ee1e (diff) | |
download | scala-5cb3d4ec14488ce2fc5a1cc8ebdd12845859c57d.tar.gz scala-5cb3d4ec14488ce2fc5a1cc8ebdd12845859c57d.tar.bz2 scala-5cb3d4ec14488ce2fc5a1cc8ebdd12845859c57d.zip |
Merge pull request #4825 from soc/topic/drop-threadpool-fallback
Remove ThreadPoolExecutor fallback in ExecutionContextImpl
Diffstat (limited to 'src/library')
-rw-r--r-- | src/library/scala/concurrent/impl/ExecutionContextImpl.scala | 43 |
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 } } |