From 5679285ec4db259d9618caef74918ea554a5e19e Mon Sep 17 00:00:00 2001 From: Philipp Haller Date: Thu, 4 Mar 2010 15:05:47 +0000 Subject: Removed obsolete SimpleExecutorScheduler, Threa... Removed obsolete SimpleExecutorScheduler, ThreadPoolScheduler, DefaultThreadPoolScheduler, and SchedulerService. Made ThreadPoolConfig private. No review necessary. --- src/actors/scala/actors/Reactor.scala | 14 ++-- .../scheduler/DefaultThreadPoolScheduler.scala | 52 -------------- .../scala/actors/scheduler/ExecutorScheduler.scala | 4 +- .../scala/actors/scheduler/SchedulerService.scala | 71 ------------------- .../actors/scheduler/SimpleExecutorScheduler.scala | 43 ------------ .../scala/actors/scheduler/ThreadPoolConfig.scala | 2 +- .../actors/scheduler/ThreadPoolScheduler.scala | 81 ---------------------- 7 files changed, 13 insertions(+), 254 deletions(-) delete mode 100644 src/actors/scala/actors/scheduler/DefaultThreadPoolScheduler.scala delete mode 100644 src/actors/scala/actors/scheduler/SchedulerService.scala delete mode 100644 src/actors/scala/actors/scheduler/SimpleExecutorScheduler.scala delete mode 100644 src/actors/scala/actors/scheduler/ThreadPoolScheduler.scala (limited to 'src/actors') diff --git a/src/actors/scala/actors/Reactor.scala b/src/actors/scala/actors/Reactor.scala index a71368e6b2..71ecd00e0a 100644 --- a/src/actors/scala/actors/Reactor.scala +++ b/src/actors/scala/actors/Reactor.scala @@ -10,8 +10,9 @@ package scala.actors -import scala.actors.scheduler.{DelegatingScheduler, DefaultThreadPoolScheduler, +import scala.actors.scheduler.{DelegatingScheduler, ExecutorScheduler, ForkJoinScheduler, ThreadPoolConfig} +import java.util.concurrent.{ThreadPoolExecutor, TimeUnit, LinkedBlockingQueue} private[actors] object Reactor { @@ -19,9 +20,14 @@ private[actors] object Reactor { def makeNewScheduler: IScheduler = { val sched = if (!ThreadPoolConfig.useForkJoin) { // default is non-daemon - val s = new DefaultThreadPoolScheduler(false) - s.start() - s + val workQueue = new LinkedBlockingQueue[Runnable] + ExecutorScheduler( + new ThreadPoolExecutor(ThreadPoolConfig.corePoolSize, + ThreadPoolConfig.maxPoolSize, + 60000L, + TimeUnit.MILLISECONDS, + workQueue, + new ThreadPoolExecutor.CallerRunsPolicy)) } else { // default is non-daemon, non-fair val s = new ForkJoinScheduler(ThreadPoolConfig.corePoolSize, ThreadPoolConfig.maxPoolSize, false, false) diff --git a/src/actors/scala/actors/scheduler/DefaultThreadPoolScheduler.scala b/src/actors/scala/actors/scheduler/DefaultThreadPoolScheduler.scala deleted file mode 100644 index 0e38d809e4..0000000000 --- a/src/actors/scala/actors/scheduler/DefaultThreadPoolScheduler.scala +++ /dev/null @@ -1,52 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2005-2010, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - -// $Id$ - -package scala.actors.scheduler - -import java.util.concurrent.{ThreadPoolExecutor, TimeUnit, LinkedBlockingQueue, - ThreadFactory} - -/** - * The DefaultThreadPoolScheduler class uses a default - * ThreadPoolExecutor for executing Actors. - * - * It can be configured using the two JVM properties - * actors.corePoolSize and - * actors.maxPoolSize that control the initial and - * maximum size of the thread pool, respectively. - * - * @author Philipp Haller - */ -private[actors] class DefaultThreadPoolScheduler(daemon: Boolean) - extends ExecutorScheduler { - - setDaemon(daemon) - - var executor = { - val workQueue = new LinkedBlockingQueue[Runnable] - - val threadFactory = new ThreadFactory { - def newThread(r: Runnable): Thread = { - val t = new Thread(r) - t setDaemon daemon - t - } - } - - new ThreadPoolExecutor(ThreadPoolConfig.corePoolSize, - ThreadPoolConfig.maxPoolSize, - 60000L, - TimeUnit.MILLISECONDS, - workQueue, - threadFactory, - new ThreadPoolExecutor.CallerRunsPolicy) - } - -} diff --git a/src/actors/scala/actors/scheduler/ExecutorScheduler.scala b/src/actors/scala/actors/scheduler/ExecutorScheduler.scala index 4b5eec21d9..8c29af604e 100644 --- a/src/actors/scala/actors/scheduler/ExecutorScheduler.scala +++ b/src/actors/scala/actors/scheduler/ExecutorScheduler.scala @@ -35,7 +35,7 @@ object ExecutorScheduler { */ def apply(exec: ExecutorService): ExecutorScheduler = start(new ExecutorScheduler { - def executor: ExecutorService = exec + val executor: ExecutorService = exec }) /** Creates an ExecutorScheduler using the provided @@ -47,7 +47,7 @@ object ExecutorScheduler { */ def apply(exec: ExecutorService, term: Boolean): ExecutorScheduler = start(new ExecutorScheduler { - def executor: ExecutorService = exec + val executor: ExecutorService = exec override val terminate = term }) diff --git a/src/actors/scala/actors/scheduler/SchedulerService.scala b/src/actors/scala/actors/scheduler/SchedulerService.scala deleted file mode 100644 index 9fbee3d0b1..0000000000 --- a/src/actors/scala/actors/scheduler/SchedulerService.scala +++ /dev/null @@ -1,71 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2005-2010, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - -// $Id$ - -package scala.actors -package scheduler - -import java.lang.{Runnable, Thread, InterruptedException} - -/** - * The abstract SchedulerService class allows subclasses - * to implement a custom onShutdown method, which is - * invoked when the runtime system has detected that all actors have - * been terminated. - * - * @version 0.9.18 - * @author Philipp Haller - */ -abstract class SchedulerService(daemon: Boolean) extends Thread with IScheduler with ActorGC { - - setDaemon(daemon) - - def this() = - this(false) - - private var terminating = false - - protected val CHECK_FREQ = 100 - - def onShutdown(): Unit - - override def run() { - try { - while (true) { - this.synchronized { - try { - wait(CHECK_FREQ) - } catch { - case _: InterruptedException => - } - if (terminating) - throw new QuitControl - - gc() - - if (allActorsTerminated) - throw new QuitControl - } - } - } catch { - case _: QuitControl => - Debug.info(this+": initiating shutdown...") - // invoke shutdown hook - onShutdown() - // allow thread to exit - } - } - - /** Shuts down the scheduler. - */ - def shutdown(): Unit = synchronized { - terminating = true - } -} - diff --git a/src/actors/scala/actors/scheduler/SimpleExecutorScheduler.scala b/src/actors/scala/actors/scheduler/SimpleExecutorScheduler.scala deleted file mode 100644 index 7f1c14eacd..0000000000 --- a/src/actors/scala/actors/scheduler/SimpleExecutorScheduler.scala +++ /dev/null @@ -1,43 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2005-2010, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - -// $Id$ - -package scala.actors -package scheduler - -import java.util.concurrent.ExecutorService - -/** - * The SimpleExecutorScheduler class uses an - * ExecutorService to execute Actors. It - * does not start an additional thread. - * - * A SimpleExecutorScheduler attempts to shut down - * the underlying ExecutorService only if - * terminate is set to true. - * - * Otherwise, the ExecutorService must be shut down either - * directly or by shutting down the - * SimpleExecutorScheduler instance. - * - * @author Philipp Haller - */ -class SimpleExecutorScheduler(protected override val executor: ExecutorService, - protected override val terminate: Boolean) - extends ExecutorScheduler { - - /* This constructor (and the var above) is currently only used to work - * around a bug in scaladoc, which cannot deal with early initializers - * (to be used in subclasses such as DefaultExecutorScheduler) properly. - */ - def this() { - this(null, true) - } - -} diff --git a/src/actors/scala/actors/scheduler/ThreadPoolConfig.scala b/src/actors/scala/actors/scheduler/ThreadPoolConfig.scala index 12a24cd89f..6efe9b007d 100644 --- a/src/actors/scala/actors/scheduler/ThreadPoolConfig.scala +++ b/src/actors/scala/actors/scheduler/ThreadPoolConfig.scala @@ -17,7 +17,7 @@ import util.Properties.{ javaVersion, javaVmVendor, isJavaAtLeast, propIsSetTo, * @author Erik Engbrecht * @author Philipp Haller */ -object ThreadPoolConfig { +private[actors] object ThreadPoolConfig { private val rt = Runtime.getRuntime() private val minNumThreads = 4 diff --git a/src/actors/scala/actors/scheduler/ThreadPoolScheduler.scala b/src/actors/scala/actors/scheduler/ThreadPoolScheduler.scala deleted file mode 100644 index 41e7b0c451..0000000000 --- a/src/actors/scala/actors/scheduler/ThreadPoolScheduler.scala +++ /dev/null @@ -1,81 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2005-2010, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - -// $Id$ - -package scala.actors.scheduler - -import java.util.concurrent.ThreadPoolExecutor -import scala.actors.Debug -import scala.concurrent.ManagedBlocker - -/** - * The ThreadPoolScheduler class uses a - * ThreadPoolExecutor to execute Actors. - * - * A ThreadPoolScheduler attempts to shut down - * the underlying ThreadPoolExecutor only if - * terminate is set to true. - * - * Otherwise, the ThreadPoolExecutor must be shut down - * either directly or by shutting down the - * ThreadPoolScheduler instance. - * - * @author Philipp Haller - */ -class ThreadPoolScheduler(protected var executor: ThreadPoolExecutor, - protected override val terminate: Boolean, - protected val daemon: Boolean) - extends Thread with ExecutorScheduler with TerminationMonitor { - - setDaemon(daemon) - - private var terminating = false // guarded by this - protected override val CHECK_FREQ = 10 - - /* This constructor (and the var above) is currently only used to work - * around a bug in scaladoc, which cannot deal with early initializers - * (to be used in subclasses such as DefaultThreadPoolScheduler) - * properly. - */ - def this(d: Boolean) { - this(null, true, d) - } - - override def run() { - try { - while (true) { - this.synchronized { - try { - wait(CHECK_FREQ) - } catch { - case _: InterruptedException => - } - - if (terminating || (terminate && allActorsTerminated)) - throw new QuitControl - - gc() - } - } - } catch { - case _: QuitControl => - Debug.info(this+": initiating shutdown...") - // invoke shutdown hook - onShutdown() - // allow thread to exit - } - } - - /** Shuts down the scheduler. - */ - override def shutdown(): Unit = synchronized { - terminating = true - } - -} -- cgit v1.2.3