微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在servlet容器中运行时,远程actor系统不会终止

如何解决在servlet容器中运行时,远程actor系统不会终止

我创建了一个使用akka(2.6.8)远程处理的简单的Web servlet应用程序。我将配置定义如下:

akka {
  loggers = ["akka.event.slf4j.Slf4jLogger"]
  loglevel = DEBUG
  debug {
    lifecycle = on
    receive = on
  }
  actor {
    provider = "cluster"
  }
  remote {
    artery {
      transport = tcp
      canonical.hostname = "localhost"
      canonical.port = 25563
    }
  }
} 

还有一个简单的servlet:

class TestServlet extends HttpServlet {

    private val log = LoggerFactory.getLogger(classOf[TestServlet])

    val system = ActorSystem("test")

    override def init(): Unit = {
        log.debug("Created system: " + system.name)
    }

    override def doGet(req: HttpServletRequest,res: HttpServletResponse) = {
        res.setContentType("text/html")
        val pw = res.getWriter()
        pw.println("<html><body>")
        pw.println("Test Servlet")
        pw.println("</body></html>")
        pw.close()
    }

    override def destroy(): Unit = {
        super.destroy()
        log.debug("Terminating")
        implicit val ec = system.dispatcher
        system.terminate().foreach { term =>
            log.debug("Terminated: " + term)
        }
    }
}

当我在Tomcat(8.5)容器中运行我的应用程序,然后将其卸载时,actor系统将不会终止。

下面的完整日志记录输出。所有代码都可以在github上找到here

15:34:29.182 [test-akka.actor.default-dispatcher-4] INFO  akka.event.slf4j.Slf4jLogger - Slf4jLogger started  
15:34:29.202 [test-akka.actor.default-dispatcher-4] DEBUG akka.event.EventStream - logger log1-Slf4jLogger started  
15:34:29.204 [test-akka.actor.default-dispatcher-4] DEBUG akka.event.EventStream - Default Loggers started  
15:34:29.254 [test-akka.actor.default-dispatcher-4] DEBUG a.r.artery.tcp.ArteryTcpTransport - Using flight recorder NoOpRemotingFlightRecorder  
15:34:29.457 [test-akka.actor.default-dispatcher-4] DEBUG akka.io.TcpListener - Successfully bound to /127.0.0.1:25563  
15:34:29.677 [test-akka.actor.default-dispatcher-4] INFO  a.r.artery.tcp.ArteryTcpTransport - Remoting started with transport [Artery tcp]; listening on address [akka://test@localhost:25563] with UID [481047694247253558]  
15:34:29.700 [test-akka.actor.default-dispatcher-4] INFO  akka.cluster.Cluster - Cluster Node [akka://test@localhost:25563] - Starting up,Akka version [2.6.8] ...  
15:34:29.773 [test-akka.actor.default-dispatcher-4] WARN  akka.cluster.Cluster - Could not register Cluster JMX MBean with name=akka:type=Cluster as it is already registered. If you are running multiple clusters in the same JVM,set 'akka.cluster.jmx.multi-mbeans-in-same-jvm = on' in config  
15:34:29.774 [test-akka.actor.default-dispatcher-4] INFO  akka.cluster.Cluster - Cluster Node [akka://test@localhost:25563] - Started up successfully  
15:34:29.811 [test-akka.actor.default-dispatcher-4] INFO  akka.cluster.Cluster - Cluster Node [akka://test@localhost:25563] - No downing-provider-class configured,manual cluster downing required,see https://doc.akka.io/docs/akka/current/typed/cluster.html#downing  
15:34:29.811 [test-akka.actor.default-dispatcher-4] INFO  akka.cluster.Cluster - Cluster Node [akka://test@localhost:25563] - No seed-nodes configured,manual cluster join required,see https://doc.akka.io/docs/akka/current/typed/cluster.html#joining  
15:34:29.867 [test-akka.actor.default-dispatcher-4] DEBUG a.s.Serialization(akka://test) - Replacing JavaSerializer with disabledJavaSerializer,due to `akka.actor.allow-java-serialization = off`.  
15:34:29.913 [https-jsse-nio-8443-exec-4] DEBUG TestServlet - Created system: test  
15:34:46.757 [https-jsse-nio-8443-exec-9] DEBUG TestServlet - Terminating  
15:34:46.759 [test-akka.actor.default-dispatcher-13] DEBUG akka.actor.CoordinatedShutdown - Running CoordinatedShutdown with reason [ActorSystemTerminateReason]  
15:34:46.759 [test-akka.actor.default-dispatcher-13] DEBUG akka.actor.CoordinatedShutdown - Performing phase [before-service-unbind] with [0] tasks  
15:34:46.760 [test-akka.actor.default-dispatcher-13] DEBUG akka.actor.CoordinatedShutdown - Performing phase [service-unbind] with [0] tasks  
15:34:46.760 [test-akka.actor.default-dispatcher-13] DEBUG akka.actor.CoordinatedShutdown - Performing phase [service-requests-done] with [0] tasks  
15:34:46.761 [test-akka.actor.default-dispatcher-13] DEBUG akka.actor.CoordinatedShutdown - Performing phase [service-stop] with [0] tasks  
15:34:46.761 [test-akka.actor.default-dispatcher-13] DEBUG akka.actor.CoordinatedShutdown - Performing phase [before-cluster-shutdown] with [0] tasks  
15:34:46.762 [test-akka.actor.default-dispatcher-13] DEBUG akka.actor.CoordinatedShutdown - Performing phase [cluster-sharding-shutdown-region] with [0] tasks  
15:34:46.764 [test-akka.actor.default-dispatcher-13] DEBUG akka.actor.CoordinatedShutdown - Performing phase [cluster-leave] with [1] tasks.  
15:34:46.767 [test-akka.actor.default-dispatcher-13] DEBUG akka.actor.CoordinatedShutdown - Performing task [leave] in CoordinatedShutdown phase [cluster-leave]  
15:34:46.784 [test-akka.actor.default-dispatcher-17] DEBUG akka.actor.CoordinatedShutdown - Performing phase [cluster-exiting] with [1] tasks.  
15:34:46.785 [test-akka.actor.default-dispatcher-17] DEBUG akka.actor.CoordinatedShutdown - Performing task [wait-exiting] in CoordinatedShutdown phase [cluster-exiting]  
15:34:46.786 [test-akka.actor.default-dispatcher-17] DEBUG akka.actor.CoordinatedShutdown - Performing phase [cluster-exiting-done] with [1] tasks.  
15:34:46.786 [test-akka.actor.default-dispatcher-17] DEBUG akka.actor.CoordinatedShutdown - Performing task [exiting-completed] in CoordinatedShutdown phase [cluster-exiting-done]  
15:34:46.787 [test-akka.actor.default-dispatcher-17] INFO  akka.cluster.Cluster - Cluster Node [akka://test@localhost:25563] - Exiting completed  
15:34:46.789 [test-akka.actor.default-dispatcher-17] INFO  akka.cluster.Cluster - Cluster Node [akka://test@localhost:25563] - Shutting down...  
15:34:46.795 [test-akka.actor.default-dispatcher-17] INFO  akka.actor.LocalActorRef - Message [akka.cluster.ClusterUserAction$Leave] to Actor[akka://test/system/cluster/core/daemon#12551980] was unhandled. [1] dead letters encountered. This logging can be turned off or adjusted with configuration settings 'akka.log-dead-letters' and 'akka.log-dead-letters-during-shutdown'.  
15:34:46.795 [test-akka.actor.default-dispatcher-17] INFO  akka.cluster.Cluster - Cluster Node [akka://test@localhost:25563] - Successfully shut down  
15:34:46.795 [test-akka.actor.default-dispatcher-17] DEBUG akka.actor.CoordinatedShutdown - Performing phase [cluster-shutdown] with [1] tasks.  
15:34:46.795 [test-akka.actor.default-dispatcher-17] DEBUG akka.actor.CoordinatedShutdown - Performing task [wait-shutdown] in CoordinatedShutdown phase [cluster-shutdown]  
15:34:51.808 [test-akka.actor.default-dispatcher-17] WARN  akka.actor.CoordinatedShutdown - Coordinated shutdown phase [cluster-shutdown] timed out after 5000 milliseconds  
15:34:51.809 [test-akka.actor.default-dispatcher-17] DEBUG akka.actor.CoordinatedShutdown - Performing phase [before-actor-system-terminate] with [0] tasks  
15:34:51.809 [test-akka.actor.default-dispatcher-17] DEBUG akka.actor.CoordinatedShutdown - Performing phase [actor-system-terminate] with [1] tasks.  
15:34:51.809 [test-akka.actor.default-dispatcher-17] DEBUG akka.actor.CoordinatedShutdown - Performing task [terminate-system] in CoordinatedShutdown phase [actor-system-terminate]  
15:35:01.828 [test-akka.actor.default-dispatcher-17] WARN  akka.actor.CoordinatedShutdown - Coordinated shutdown phase [actor-system-terminate] timed out after 10000 milliseconds  

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?