简体   繁体   English

Clojure Web应用程序中的内存泄漏

[英]Memory leak in Clojure web application

I've created a web application in Clojure, packaged it as a WAR, and deployed it on top of Tomcat. 我在Clojure中创建了一个Web应用程序,将其打包为WAR,并将其部署在Tomcat之上。 It works as I expect, but when I go to shut down Tomcat, I see many exceptions like the following: 它按照我的预期工作,但是当我关闭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.

I understand there are some things clojure does that may get a little ahead of the Java garbage collector at times. 我知道clojure有些事情可能会有点像Java垃圾收集器。 My war does have a ServletContextListener that starts a few background threads, but I see no reason why these shouldn't just be gracefully terminated (they aren't daemon threads, after all) when the context undeploys. 我的战争确实有一个ServletContextListener,可以启动一些后台线程,但是当上下文取消部署时,我认为没有理由不应该优雅地终止它们(毕竟它们不是守护线程)。

Is there perhaps a better/different way I should be using to start my threads that's more Tomcat-friendly? 有没有更好/不同的方式我应该用来启动我更喜欢Tomcat的线程? Right now I am just starting them by calling (future (loop ... . 现在我只是通过调用(future (loop ...启动它们。

Apparently Tomcat has memory leak protection - check out the link. 显然Tomcat有内存泄漏保护 - 请查看链接。

I don't think it is actually a memory leak, it's more likely that Tomcat is being zealous about reporting the fact that certain threads/threadlocal haven't been properly shut down/released. 我不认为它实际上是内存泄漏,Tomcat更有可能热衷于报告某些线程/ threadlocal尚未正确关闭/释放的事实。

The warning is annoying, but it's not really a fatal issue as all threadlocal memory will be released anyway as soon as the JVM shuts down. 警告很烦人,但这并不是一个致命的问题,因为一旦JVM关闭,所有线程本地内存都会被释放。

Starting your threads with (future (loop ...)) is fine in general, but you should ensure that they actually exit at the right moment. 用(future(loop ...))开始你的线程一般都很好,但是你应该确保它们在正确的时刻实际退出。 This could mean having something like an "is-shutting-down?" 这可能意味着有一种“正在关闭?” atom that you can check on each loop. 你可以检查每个循环的原子。 You might find that this removes the warning. 您可能会发现这会删除警告。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM