catalina.out中的这些警告是什么?

2022-09-02 19:24:50

我在Tomcat 7中有一个Web应用程序。
当我关闭Tomcat时,我看到这些警告(但并非总是如此)

SEVERE: The web application [/MyApplication] created a ThreadLocal
with key of type
[org.apache.xml.security.algorithms.MessageDigestAlgorithm$1] (value
[org.apache.xml.security.algorithms.MessageDigestAlgorithm$1@2e2c2e2c])
and a value of type [java.util.HashMap] (value
[{http://www.w3.org/2000/09/xmldsig#sha1=MESSAGE DIGEST SHA-1}]) 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.
Apr 3, 2012 1:56:19 PM org.apache.catalina.loader.WebappClassLoader
checkThreadLocalMapForLeaks   SEVERE: The web application
[/MyApplication] created a ThreadLocal with key of type
[com.sun.xml.bind.v2.ClassFactory$1] (value
[com.sun.xml.bind.v2.ClassFactory$1@25442544]) and a value of type
[java.util.WeakHashMap] (value [{class
com.classes.internal.ContactType=java.lang.ref.WeakReference@17eb17eb,
class
javax.xml.bind.annotation.adapters.HexBinaryAdapter=java.lang.ref.WeakReference@178a178a,
class
com.classes.internal.xjc.ListType=java.lang.ref.WeakReference@181c181c,
class
com.classes.internal.xjc.MessageType=java.lang.ref.WeakReference@17711771,
class
com.classes.internal.xjc.MessageType=java.lang.ref.WeakReference@17011701}])
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.   Apr 3, 2012 1:56:19 PM
org.apache.catalina.loader.WebappClassLoader
checkThreadLocalMapForLeaks   SEVERE: The web application
[/MyApplication] created a ThreadLocal with key of type
[org.apache.xml.security.utils.UnsyncBufferedOutputStream$1] (value
[org.apache.xml.security.utils.UnsyncBufferedOutputStream$1@4a904a90])
and a value of type [byte[]] (value [[B@67486748]) 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.  

这些警告在 catalina.out 中关机意味着什么?
我看到提到了我的一些JAXB类,但无法分辨这里的问题是什么。

请帮忙吗?


答案 1

简而言之,某些 ThreadLocal 尚未正确清理。大多数(如果不是全部)J2EE 服务器/应用程序容器将线程池用于传入请求和其他任务,以防止始终启动新线程的开销。问题是,一些库(如果你不知道更好的话,还有你自己)在任务/请求的执行结束后不会清理它们的ThreadLocal。

通常,当线程在执行结束时死亡时,存储在ThreadLocals中的对象不再被引用,垃圾回收器负责删除此类对象:

每个线程都持有对其线程局部变量副本的隐式引用,只要该线程处于活动状态并且 ThreadLocal 实例可访问;线程消失后,其线程本地实例的所有副本都将受到垃圾回收(除非存在对这些副本的其他引用)。

但是,当从线程池中提取线程时,它不会死亡,而是返回到池中。由于线程仍处于活动状态,因此引用的 ThreadLocal 也处于活动状态。这表现为内存泄漏和值从一个请求“泄漏”到另一个请求,当使用相同的 ThreadLocal 并且之前使用了处理请求/任务的线程时。


答案 2

您的应用程序中有一个或多个内存泄漏。有关发生这些错误的原因的完整解释,哪些是您的错误以及您可以采取哪些措施来修复它们,请参阅此演示文稿:http://people.apache.org/~markt/presentations/2010-11-04-Memory-Leaks-60mins.pdf