【问题标题】:Akka Tomcat issueAkka Tomcat 问题
【发布时间】:2017-11-14 22:29:48
【问题描述】:

我有一个类似的问题,如下面的帖子所述:

https://groups.google.com/d/msg/akka-user/Lp2hn4FfhU8/6a1EZVCmJpQJ

关闭Tomcat时,我得到:

10-Nov-2017 09:47:56.517 SEVERE [main] 

org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [akka.actor.ActorCell$$anon$1] (value [akka.actor.ActorCell$$anon$1@1f9e9475]) and a value of type [scala.collection.immutable.Nil$] (value [List()]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
10-Nov-2017 09:47:56.517 SEVERE [main] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [akka.actor.ActorCell$$anon$1] (value [akka.actor.ActorCell$$anon$1@1f9e9475]) and a value of type [scala.collection.immutable.Nil$] (value [List()]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
10-Nov-2017 09:47:56.535 INFO [main] org.apache.coyote.AbstractProtocol.stop Stopping ProtocolHandler ["http-nio-8080"]
10-Nov-2017 09:47:56.538 INFO [main] org.apache.coyote.AbstractProtocol.stop Stopping ProtocolHandler ["ajp-nio-8009"]
10-Nov-2017 09:47:56.540 INFO [main] org.apache.coyote.AbstractProtocol.destroy Destroying ProtocolHandler ["http-nio-8080"]
10-Nov-2017 09:47:56.541 INFO [main] org.apache.coyote.AbstractProtocol.destroy Destroying ProtocolHandler ["ajp-nio-8009"]

Tomcat 被卡住了——要完全关闭它,我必须终止它的进程。 我尝试了上面帖子中提到的类似解决方案(我使用 Akka 2.5.6,因此不再有 shutdown() 和 awaitTermination() 方法):

@Override
public void contextDestroyed(ServletContextEvent servletContextEvent) {
    ActorSystem actorSystem = (ActorSystem) WebApplicationContextUtils.getRequiredWebApplicationContext(servletContextEvent.getServletContext()).getBean("my-actor-system");
    try {
        Await.result((Awaitable) actorSystem.terminate(), Duration.create(10, TimeUnit.SECONDS));
    } catch (Exception e) {
        logger.warning(e.getMessage());
    }
}

但这根本没有帮助。 Bean 的创建方式很简单:

@Bean
public ActorSystem actorSystem() {
    return ActorSystem.create("my-actor-system");
}

有什么想法吗?

版本规格:
雄猫 9.0.1
Akka 2.5.6
春季4.2.3

【问题讨论】:

  • 虽然我没有答案,但至少我有同样的问题。你并不孤单:-)
  • 哈,谢谢伙计。我已经发布了我的解决方法,所以也许它对你也有帮助。

标签: java spring tomcat akka


【解决方案1】:

我已经设法找出解决方法,有人可能会觉得它有用。虽然我知道,但这不是一个合适的解决方案,所以仍然欢迎所有“更清洁”的解决方案

当我在 ServletContextListener 中创建和销毁 ActorSystem 时,它工作正常。所以最后我用这个覆盖了默认监听器:

private static ActorSystem actorSystem;

@Override
public void contextInitialized(ServletContextEvent servletContextEvent) {
    actorSystem = ActorSystem.create("my-actor-system");
}

@Override
public void contextDestroyed(ServletContextEvent servletContextEvent) {
    try {
        Await.result((Awaitable) actorSystem.terminate(), Duration.create(10, TimeUnit.SECONDS));
    } catch (Exception e) {
        logger.warning(e.getMessage());
    }
}

public static ActorSystem getActorSystem() {
    return actorSystem;
}

然后在 config 中创建 ActorSystem Bean,它调用上面的 getter 方法:

@Bean
public ActorSystem actorSystem() {
    return MyServletContextListener.getActorSystem();
}

请注意,我使用的是 Akka 2.5.6。在旧版本中,您应该以不同的方式终止 ActorSystem(您会注意到,如果是这样,将没有 actorSystem.terminate() 方法)。

【讨论】:

    猜你喜欢
    • 2012-03-08
    • 2017-09-22
    • 2020-10-26
    • 2019-04-25
    • 2017-04-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多