diff --git a/akka-actor/src/main/scala/akka/actor/ActorSystem.scala b/akka-actor/src/main/scala/akka/actor/ActorSystem.scala index 5df607a02d..b088dd9bff 100644 --- a/akka-actor/src/main/scala/akka/actor/ActorSystem.scala +++ b/akka-actor/src/main/scala/akka/actor/ActorSystem.scala @@ -427,12 +427,17 @@ abstract class ActorSystem extends ActorRefFactory { * will recursively stop all its child actors, then the system guardian * (below which the logging actors reside) and the execute all registered * termination handlers (see [[ActorSystem#registerOnTermination]]). + * Be careful to not schedule any operations on completion of the returned future + * using the `dispatcher` of this actor system as it will have been shut down before the + * future completes. */ def terminate(): Future[Terminated] /** * Returns a Future which will be completed after the ActorSystem has been terminated - * and termination hooks have been executed. + * and termination hooks have been executed. Be careful to not schedule any operations + * on the `dispatcher` of this actor system as it will have been shut down before this + * future completes. */ def whenTerminated: Future[Terminated] diff --git a/akka-docs/rst/project/migration-guide-2.3.x-2.4.x.rst b/akka-docs/rst/project/migration-guide-2.3.x-2.4.x.rst index 7eced6d4f1..0206bc6ea8 100644 --- a/akka-docs/rst/project/migration-guide-2.3.x-2.4.x.rst +++ b/akka-docs/rst/project/migration-guide-2.3.x-2.4.x.rst @@ -645,4 +645,31 @@ Now: def deliver(destination: ActorPath)(deliveryIdToMessage: Long ⇒ Any): Unit The Java API remains unchanged and has simply gained the 2nd overload which allows ``ActorSelection`` to be -passed in directly (without converting to ``ActorPath``). \ No newline at end of file +passed in directly (without converting to ``ActorPath``). + + +Actor system shutdown +--------------------- +``ActorSystem.shutdown``, ``ActorSystem.awaitTermination`` and ``ActorSystem.isTerminated`` has been +deprecated in favor of ``ActorSystem.terminate`` and ``ActorSystem.whenTerminated```. Both returns a +``Future[Terminated]`` value that will complete when the actor system has terminated. + +To get the same behavior as ``ActorSystem.awaitTermination`` block and wait for ``Future[Terminated]`` value +with ``Await.result`` from the Scala standard library. + +To trigger a termination and wait for it to complete: + + import scala.concurrent.duration._ + Await.result(system.terminate(), 10.seconds) + +Be careful to not do any operations on the ``Future[Terminated]`` using the ``system.dispatcher`` +as ``ExecutionContext`` as it will be shut down with the ``ActorSystem``, instead use for example +the Scala standard library context from ``scala.concurrent.ExecutionContext.global``. + + + // import system.dispatcher <- this would not work + import scala.concurrent.ExecutionContext.Implicits.global + + system.terminate().foreach { _ => + println("Actor system was shut down") + }