From f4e6443f7e812a8a699b04af5d6ee4f875c1ed52 Mon Sep 17 00:00:00 2001 From: Roland Kuhn Date: Wed, 16 Mar 2016 16:39:17 +0100 Subject: [PATCH] remove 1 synchronized from akka.dispatch --- .../src/main/scala/akka/dispatch/Dispatcher.scala | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/akka-actor/src/main/scala/akka/dispatch/Dispatcher.scala b/akka-actor/src/main/scala/akka/dispatch/Dispatcher.scala index e5b97847fe..c962535388 100644 --- a/akka-actor/src/main/scala/akka/dispatch/Dispatcher.scala +++ b/akka-actor/src/main/scala/akka/dispatch/Dispatcher.scala @@ -11,6 +11,7 @@ import akka.dispatch.sysmsg.SystemMessage import java.util.concurrent.{ ExecutorService, RejectedExecutionException } import scala.concurrent.duration.Duration import scala.concurrent.duration.FiniteDuration +import java.util.concurrent.atomic.AtomicReferenceFieldUpdater /** * The event-based ``Dispatcher`` binds a set of Actors to a thread pool backed up by a @@ -88,16 +89,17 @@ class Dispatcher( new Mailbox(mailboxType.create(Some(actor.self), Some(actor.system))) with DefaultSystemMessageQueue } + private val esUpdater = AtomicReferenceFieldUpdater.newUpdater( + classOf[Dispatcher], + classOf[LazyExecutorServiceDelegate], + "executorServiceDelegate") + /** * INTERNAL API */ protected[akka] def shutdown: Unit = { val newDelegate = executorServiceDelegate.copy() // Doesn't matter which one we copy - val es = synchronized { - val service = executorServiceDelegate - executorServiceDelegate = newDelegate // just a quick getAndSet - service - } + val es = esUpdater.getAndSet(this, newDelegate) es.shutdown() }