Merge pull request #19938 from akka/wip-remove-1-synchronized-RK

remove one needless synchronized in akka-actor
This commit is contained in:
Roland Kuhn 2016-03-17 10:48:40 +01:00
commit 0d80d094e6

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