Introduction📑
The Coordinated Shutdown ActorSystem module allows particular Akka.NET actors and services to be suspended while tasks are completed during shutdown in a predetermined order. While ApplicationLifecycle API still exists and Play is in charge of exiting the JVM, Coordinated Termination is in charge of Play's entire shutdown.

Keep reading the article to understand the process of Coordinated Shutdown, the Shutdown Triggers, and its limitations, followed by essential differences between Coordinated Shutdown and the Application Life Cycle.
Shutdown Sequence📚
When a Coordinated Shutdown is launched, its default phases are arranged in a directed acyclic graph (DAG). Current phases can rely on your new phases by creating new ones and overwriting the default settings. The most important phases included in Akka and used by Play are listed below:
before-service-unbind
service-unbind
service-requests-done
service-stop
// Only a few cluster-related phases are intended for internal use.
before-actor-system-terminate
actor-system-terminate
The essential phases are listed above in the order they will typically run. To alter this behavior, follow the Akka documentation.
NOTE📝
✍️In the service-stop phase, the ApplicationLifecycle#stopHooks that you do not migrate to Coordinated Shutdown tasks will continue to run in reverse order of creation inside CoordinatedShutdown. To put it differently, Coordinated Shutdown treats each ApplicationLifecycle#stopHook as a separate task.
✍️You have the choice to execute a shutdown task at a different phase due to a Coordinated Shutdown.
✍️ApplicationLifecycle#stopHooks should work well in your existing code; however, you might want to consider changing how and when it is called. For instance, the actor needs a database connection if it performs database operations regularly.
Your database connection pool may be stopped in an ApplicationLifecycle#stopHook that occurs in the service-stop phase, depending on how the two were built. At the same time, your actor may now be closed on the actor-system-terminate phase that occurs later.
If running your cleanup code at the service-stop phase is consistent with your usage, keep using ApplicationLifecycle#stopHooks.
You must inject a CoordinatedShutdown instance and use addTask as in the example below to choose to employ Coordinated Shutdown tasks:
SCALA
class ResourceAllocatingScalaClass @Inject() (cs: CoordinatedShutdown) {
// Here, some resource distribution takes place: a relationship
// pool is made, and a client library is launched, ...
val resources = Resources.allocate()
// Immediately register a shutdown job.
cs.addTask(CoordinatedShutdown.PhaseServiceUnbind, "free-some-resource") { () =>
resources.release()
}
// ... additional code
}
JAVA
public class ResourceAllocatingJavaClass {
private final Resources resources;
@Inject
public ResourceAllocatingJavaClass(CoordinatedShutdown cs) {
// Here, some resource distribution takes place: a relationship
/// pool is made, and a client library is launched, ...
resources = Resources.allocate();
// Immediately register a shutdown job.
cs.addTask(
CoordinatedShutdown.PhaseServiceUnbind(), "free-some-resource", () -> resources.release());
}
// ... additional code
}