Clojure网络应用程序中的内存泄漏问题

3

我已经使用Clojure创建了一个Web应用程序,将其打包成WAR文件,并在Tomcat上部署。它按照我的预期工作,但是当我尝试关闭Tomcat时,我看到很多异常,如下所示:

SEVERE: The web application [] created a ThreadLocal with key of type 
[java.lang.ThreadLocal] (value [java.lang.ThreadLocal@fc5408]) and a value of type [clojure.lang.LockingTransaction] (value [clojure.lang.LockingTransaction@12db7c]) but failed to remove it when the web application was stopped. This is very likely to create a memory leak.
Mar 17, 2011 4:19:48 AM org.apache.catalina.loader.WebappClassLoader clearThreadLocalMap
SEVERE: The web application [] created a ThreadLocal with key of type [null] (value [clojure.lang.Var$1@11de914]) and a value of type [clojure.lang.Var.Frame] (value [clojure.lang.Var$Frame@7c28c]) but failed to remove it when the web application was stopped. This is very likely to create a memory leak.
Mar 17, 2011 4:19:48 AM org.apache.catalina.loader.WebappClassLoader clearThreadLocalMap
SEVERE: The web application [] created a ThreadLocal with key of type [null] (value [clojure.lang.Var$1@11de914]) and a value of type [clojure.lang.Var.Frame] (value [clojure.lang.Var$Frame@17588d5]) but failed to remove it when the web application was stopped. This is very likely to create a memory leak.

我知道Clojure有时可能会超越Java垃圾回收器的一些事情。我的war文件有一个ServletContextListener,它启动了一些后台线程,但我认为当上下文卸载时,这些线程应该优雅地终止(毕竟它们不是守护线程)。
也许有更好/不同的方法可以使用来启动我的线程,更适合Tomcat?现在我只是通过调用(future(loop ...来启动它们。
1个回答

1

显然Tomcat有内存泄漏保护 - 点击链接查看。

我认为这实际上不是内存泄漏,更可能是Tomcat在报告某些线程/线程本地未正确关闭/释放的事实方面非常热心。

警告很烦人,但这并不是一个致命问题,因为所有线程本地内存都将在JVM关闭时立即释放。

通常情况下,使用(future (loop ...))启动线程是可以的,但您应确保它们在正确的时刻退出。这可能意味着拥有类似于“正在关闭吗?”原子的东西,您可以在每个循环中进行检查。您可能会发现这样可以消除警告。


当JVM完全关闭时,这当然不是问题。我想问题更多地出现在我将新版本的WAR部署到现有的运行Tomcat实例上时 - 当然它会取消部署旧版本,吐出警告,然后选择并启动新版本。我担心那些泄漏的东西在新版本的WAR启动后仍然挂在那里... - Ben Englert

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接