问题描述
我刚刚开始在我的Tomcat webapp中使用Google Guice,并且每当WAR文件取消部署时都会在catalina.out文件中注意到以下内容:
I have just started using Google Guice with my Tomcat webapp, and have noticed the following in the catalina.out file whenever the WAR file is undeployed:
2011年5月16日下午5:37:24 org.apache.catalina.startup.HostConfig checkResources
INFO:取消部署上下文[/ app]
May 16, 2011 5:37:24 PM org.apache.catalina.startup.HostConfig checkResourcesINFO: Undeploying context [/app]
2011年5月16日下午5:37:24 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
严重:Web应用程序似乎已启动名为[com.google.inject.internal的线程。 util。$ Finalizer]但未能阻止它。这很可能会造成内存泄漏。
May 16, 2011 5:37:24 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreadsSEVERE: A web application appears to have started a thread named [com.google.inject.internal.util.$Finalizer] but has failed to stop it. This is very likely to create a memory leak.
2011年5月16日下午5:37:24 org.apache.catalina.loader.WebappClassLoader clearThreadLocalMap
SEVERE :Web应用程序创建了一个ThreadLocal,其键为[null]键(值为[com.google.inject.internal.InjectorImpl$1@10ace8d]),值为[java.lang.Object []](值[[Ljava] .lang.Object; @ 7e9bed])但在Web应用程序停止时无法将其删除。为防止内存泄漏,已强制删除ThreadLocal。
May 16, 2011 5:37:24 PM org.apache.catalina.loader.WebappClassLoader clearThreadLocalMapSEVERE: A web application created a ThreadLocal with key of type [null] (value [com.google.inject.internal.InjectorImpl$1@10ace8d]) and a value of type [java.lang.Object[]] (value [[Ljava.lang.Object;@7e9bed]) but failed to remove it when the web application was stopped. To prevent a memory leak, the ThreadLocal has been forcibly removed.
有谁知道是什么原因引起的,或者我怎么能阻止它发生?
Does anyone know what causes this, or how I can stop it from happening?
我只按照此处的说明进行操作
I have only followed the instructions from herehttp://code.google.com/docreader/#p=google-guice&s=google-guice&t=ServletModule
......并且还没有做任何花哨的事情。我只有2个servlet和一个过滤器。
... and haven't done anything fancy with it yet. I just have 2 servlets and a filter.
谢谢!
推荐答案
如果你在关闭webapp时得到这个,我不会太担心。这种类型的资源泄漏应用程序。关机很常见。当你经常进行热部署时(即在不杀死JVM的情况下多次部署),它们确实会成为一个问题,但是当冷部署完成时它们不会出现问题(在部署之前完成取消部署/部署重新部署)。
If you are getting this when you shutdown the webapp, I wouldn't worry too much. This type of resource leak on app. shutdown is common. They do become a problem when you frequently do hot deploys (i.e. un-deploy many times without killing the JVM), but they won't be problematic when a cold deploy is done (un-deploy/deploy is done while killing the JVM before re-deploy).
一种常见的策略是你在开发过程中进行热部署(因为它们通常比冷部署更快),并且只在资源泄漏开始时进行冷部署影响你的表现。然后,在生产中,您将在每次部署时执行冷部署。鉴于具有此类泄漏的代码/库的数量,尝试消除它们将是很难的IMO。
A common tactic is that you do hot-deploys during development (as they are typically faster than cold-deploys), and only do a cold deploy when the resource leak starts to affect your performance. Then, in production you do a cold deploy on every deploy. Given the number of code/libraries that has this type of leak, trying to eliminate them would be hard IMO.
这篇关于Guice + Tomcat潜在的内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!