diff options
7 files changed, 13 insertions, 254 deletions
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 <code>DefaultThreadPoolScheduler</code> class uses a default - * <code>ThreadPoolExecutor</code> for executing <code>Actor</code>s. - * - * It can be configured using the two JVM properties - * <code>actors.corePoolSize</code> and - * <code>actors.maxPoolSize</code> 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 <code>ExecutorScheduler</code> 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 <code>SchedulerService</code> class allows subclasses - * to implement a custom <code>onShutdown</code> 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 <code>SimpleExecutorScheduler</code> class uses an - * <code>ExecutorService</code> to execute <code>Actor</code>s. It - * does not start an additional thread. - * - * A <code>SimpleExecutorScheduler</code> attempts to shut down - * the underlying <code>ExecutorService</code> only if - * <code>terminate</code> is set to true. - * - * Otherwise, the <code>ExecutorService</code> must be shut down either - * directly or by shutting down the - * <code>SimpleExecutorScheduler</code> 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 <code>ThreadPoolScheduler</code> class uses a - * <code>ThreadPoolExecutor</code> to execute <code>Actor</code>s. - * - * A <code>ThreadPoolScheduler</code> attempts to shut down - * the underlying <code>ThreadPoolExecutor</code> only if - * <code>terminate</code> is set to true. - * - * Otherwise, the <code>ThreadPoolExecutor</code> must be shut down - * either directly or by shutting down the - * <code>ThreadPoolScheduler</code> 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 - } - -} |