我正在使用 Tomee、Primefaces 5.0 和 Apache SHiro。
当我启动服务器时,它消耗 600 Mb 内存。 如果我打开并关闭某个页面,该页面包含大量信息,但与 ViewScoped bean 相关,则内存使用量将达到 1.6 GiB。如果我打开其他东西,甚至是 RequestScopped beans,也会发生同样的事情。 我已经检查过,并且正在调用 PreDestroy 方法,所以我的问题不是这个。
使用 Eclipse 内存分析器:
One instance of "org.apache.openejb.core.WebContext" loaded by "org.apache.catalina.loader.StandardClassLoader @ 0xa34f0cf0" occupies 1,189,717,200 (97.83%) bytes. The memory is accumulated in one instance of "java.util.concurrent.ConcurrentHashMap$Segment[]" loaded by "system class loader".
Keywords java.util.concurrent.ConcurrentHashMap$Segment[] org.apache.openejb.core.WebContext org.apache.catalina.loader.StandardClassLoader @ 0xa34f0cf0
当我运行 shutdown.sh 时,catalina.out 中有以下内容
org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks SEVERE: The web application [/projeto-bim] created a ThreadLocal with key of type [org.apache.shiro.util.ThreadContext.InheritableThreadLocalMap] (value [org.apache.shiro.util.ThreadContext$InheritableThreadLocalMap@5720d785]) and a value of type [java.util.HashMap] (value [{org.apache.shiro.util.ThreadContext_SECURITY_MANAGER_KEY=org.apache.shiro.web.mgt.DefaultWebSecurityManager@2d258973, org.apache.shiro.util.ThreadContext_SUBJECT_KEY=org.apache.shiro.web.subject.support.WebDelegatingSubject@7b62f42c}]) 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.
我尝试了几件事,例如在 web.xml 中设置一些配置以仅维护一个 session 或设置 Tomee 将 session 信息保存在磁盘上,但没有任何效果。
我应该做什么?
//新信息: 内存达到 1.6 GiB 并停止,因为这是我的最大堆空间。 Web 服务器开始抛出 OutOfMemoryError。我将尝试增加此值,看看它还能使用多少。
好的。现在我将 java 堆空间增加到 3 GB。我的应用程序使用了这一切。这显然是内存泄漏,因为每次我打开某个包含大量信息的页面时,内存就会增加300 Mb,并且永远不会减少! 我能做什么?
最佳答案
我没有看到太多与泄漏有关的事情。
WebContext 绑定(bind)到 TomEE 中的 Web 应用程序(正常情况下,您在应用程序运行时会看到它)
那么所有警告都只是 apache shiro 在您的 web 应用程序中,并使用 threadlocal 来按线程保存安全上下文。由于它是由 web 应用程序加载的,因此可能会造成泄漏,但除了修补 shiro 之外,您无能为力。
关于java - Tomee Jaxrs 1.7.1 + Mojarra 2.29 内存泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28300404/