[英]How to detect akka actor termination is due to system shutdown and avoid restarting it
[英]Proper shutdown of Akka actor system in web application
我在一个Web应用程序中使用Akka。 该应用程序是在Tomcat Servlet容器中初始化的标准Spring应用程序。
我有一个简单的ServletContextListener像这样:
public class AkkaInitializer implements ServletContextListener {
@Override
public void contextInitialized(ServletContextEvent servletContextEvent) {
ActorSystem system = ActorSystem.create("system");
// initialize main top-level master actor here ...
}
}
Tomcat在应用程序启动时调用contextInitialized。 现在的问题是,假设我有一个顶级演员,他的一个孩子可能会因此而失败。 我希望该主要角色本质上记录发生的故障并随后关闭JVM。 怎样才能做到这一点呢?
关闭Akka应用程序的干净方法可能是:
1)停止接收来自外界的传入请求(取决于您的实现);
2)以正确的顺序将PoisonPill
-s发送给所有顶级角色(与您应用中的主要数据流完全相同或相似;路由器也应该能够将PoisonPill
-s广播到其路由);
3)使用“ 收割者”模式来监视您的演员,并确定他们已经处理了所有消息并已停止,然后又停止了ActorSystem(在任何情况下都不要忘记让演员停止停止ActorSystem的超时时间相当长);
4)等待ActorSystem终止( ActorSystem.awaitTermination(scala.concurrent.duration.Duration timeout)
);
5)关闭应正确终止的应用程序的所有其他部分;
6)关闭JVM。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.