簡體   English   中英

在Web應用程序中正確關閉Akka actor系統

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM