remove 1 synchronized from akka.dispatch

This commit is contained in:
Roland Kuhn 2016-03-16 16:39:17 +01:00
parent b52c498638
commit f4e6443f7e

View file

@ -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()
}