Play war部署可防止Tomcat停止

时间:2014-08-22 09:07:08

标签: scala tomcat playframework akka playframework-2.2

我目前正在使用Tomcat下的播放应用程序遇到一些onStop问题。 我正在使用play 2.2.2,sbt 0.13.0,scala 2.10.4和Tomcat 7以及jdk1.6。

要创建war文件,我使用play2war插件(1.2):

Play2WarKeys.servletVersion := "2.5"

因此,部署和运行应用程序以及Tomcat本身正在运行,没有任何问题。但是一旦我尝试使用默认的shutdown.sh来停止服务器,我就会得到

SEVERE: The web application [/WEBSERVICE] appears to have started a thread named [play-scheduler-1] but has failed to stop it. This is very likely to create a memory leak.
Aug 21, 2014 6:15:18 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/WEBSERVICE] appears to have started a thread named [play-akka.actor.default-dispatcher-3] but has failed to stop it. This is very likely to create a memory leak.
Aug 21, 2014 6:15:18 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/WEBSERVICE] appears to have started a thread named [play-akka.actor.default-dispatcher-4] but has failed to stop it. This is very likely to create a memory leak.
Aug 21, 2014 6:15:18 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/WEBSERVICE] appears to have started a thread named [play-akka.actor.default-dispatcher-5] but has failed to stop it. This is very likely to create a memory leak.
Aug 21, 2014 6:15:18 PM org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
SEVERE: The web application [/WEBSERVICE] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@384e9bea]) and a value of type [scala.concurrent.forkjoin.ForkJoinPool.Submitter] (value [scala.concurrent.forkjoin.ForkJoinPool$Submitter@4e57dc21]) 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.
Aug 21, 2014 6:15:18 PM org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
SEVERE: The web application [/WEBSERVICE] created a ThreadLocal with key of type [scala.concurrent.forkjoin.ThreadLocalRandom$1] (value [scala.concurrent.forkjoin.ThreadLocalRandom$1@4679cf8c]) and a value of type [scala.concurrent.forkjoin.ThreadLocalRandom] (value [scala.concurrent.forkjoin.ThreadLocalRandom@67291479]) 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.
Aug 21, 2014 6:15:18 PM org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
SEVERE: The web application [/WEBSERVICE] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@384e9bea]) and a value of type [scala.concurrent.forkjoin.ForkJoinPool.Submitter] (value [scala.concurrent.forkjoin.ForkJoinPool$Submitter@39ff48d8]) 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.
Aug 21, 2014 6:15:18 PM org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
SEVERE: The web application [/WEBSERVICE] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@384e9bea]) and a value of type [scala.concurrent.forkjoin.ForkJoinPool.Submitter] (value [scala.concurrent.forkjoin.ForkJoinPool$Submitter@27077aa7]) 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.
Aug 21, 2014 6:15:18 PM org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
SEVERE: The web application [/WEBSERVICE] created a ThreadLocal with key of type [akka.actor.ActorCell$$anon$1] (value [akka.actor.ActorCell$$anon$1@5c057df5]) 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.
Aug 21, 2014 6:15:18 PM org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
SEVERE: The web application [/WEBSERVICE] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@384e9bea]) and a value of type [scala.concurrent.forkjoin.ForkJoinPool.Submitter] (value [scala.concurrent.forkjoin.ForkJoinPool$Submitter@6c908f05]) 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.
Aug 21, 2014 6:15:18 PM org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
SEVERE: The web application [/WEBSERVICE] created a ThreadLocal with key of type [scala.concurrent.forkjoin.ThreadLocalRandom$1] (value [scala.concurrent.forkjoin.ThreadLocalRandom$1@4679cf8c]) and a value of type [scala.concurrent.forkjoin.ThreadLocalRandom] (value [scala.concurrent.forkjoin.ThreadLocalRandom@69dc8f2]) 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.

之后应用程序和tomcat关闭但我仍然看到tomcat prozess zombieing通过

ps -ef

完全杀死它的唯一可能性是kill -9 <pid>。 所以我开始在网上搜索一个偶然发现的类似问题,建议在使用的actor系统上执行.shutdown()awaitTermination()

所以我创建了一个覆盖onStop方法的Global对象:

object Global extends GlobalSettings {
 val actorSystem = Application.system

 override def onStop(app: Application) {
    implicit val timeout = Timeout(4 seconds)

    Logger.info("Shutting down Actorsystem")

    Akka.system.shutdown()
    Akka.system.awaitTermination(timeout.duration)
    actorSystem.shutdown()
    actorSystem.awaitTermination(timeout.duration)
  }

}

但它无法解决问题。我试图通过Akka.system关闭我自己的ActorSystem以及默认的播放actor系统,但它没有效果。
当我看到catalina.out中的Log语句时,onStop方法会执行。

因此,为了解决这个问题,我设置了一个简单的新游戏2.3.3,只需要简单的字符串响应。除了播放默认播放器系统之外没有演员系统,并集成了play2war插件,以查看问题是由我的代码还是播放本身引起的。问题也是一样。

所以我正在锁定一些建议如何关闭这些调度程序和调度程序等等,这些是由play生成但是在关闭时没有被杀死?

我真的很感激任何帮助!

修改

我还通过删除应用程序库中的oracle驱动程序尝试了Oracle driver memory leak - Tomcat中提供的解决方案 - 但没有对tomcat行为进行任何更改

Play2war Github中还有多个主题基于这个主题但不幸的是没有解决方案:

Leak error and Tomcat is never shutdown #108

tomcat 6: hangs on shutdown #161

1 个答案:

答案 0 :(得分:4)

所以我在这个帖子中找到了解决这个问题的方法: is-there-any-light-weight-actors-in-akka

正如Roland Kuhn所描述的那样,可以通过akka将线程设置为守护进程,这最终不会阻止虚拟机关闭。

要在application.conf中设置:

play.akka.daemonic=on

或哪些也应该有效:

akka {
  daemonic=on
}

有了这个,tomcat将会没有问题地关闭。