简体   繁体   English

Jboss java.lang.OutOfMemoryError:Java堆空间

[英]Jboss java.lang.OutOfMemoryError: Java heap space

from time to time jboss serwer throws "An unhandled exception has occurred: jboss serwer有时会抛出“发生未处理的异常:

java.lang.OutOfMemoryError: Java heap space". java.lang.OutOfMemoryError:“ Java堆空间”。

Could you please explain me how it works? 您能解释一下它是如何工作的吗?

A few infromation: Jboss is running all the time in standalone mode on Windows. 一些信息:Jboss始终在Windows上以独立模式运行。 From standalone.conf "JAVA_OPTS=-Xms1G -Xmx1G -XX:MaxPermSize=256M" I deploy ~50MB war file, after tests I remove it. standalone.conf "JAVA_OPTS=-Xms1G -Xmx1G -XX:MaxPermSize=256M"我部署了约50MB的war文件,经过测试,我删除了它。

What is possible cause of this Java heap space exception? 此Java堆空间异常的可能原因是什么? Should I restart server between following deploys? 我应该在以下部署之间重新启动服务器吗? Is there any command to clean heap space? 是否有任何清除堆空间的命令? If I understand corectly increasing of -Xmx argument will not help. 如果我完全理解-Xmx参数的增加将无济于事。 It will only delay the appearance of the exception. 这只会延迟异常的出现。 Right? 对?

Thanks in advance 提前致谢

What is possible cause of this Java heap space exception? 此Java堆空间异常的可能原因是什么?

On the face of it, the explanation is simple. 从表面上看,解释很简单。 The JVM has run out of heap space, and the GC is unable to reclaim enough space to continue. JVM的堆空间已用完,GC无法回收足够的空间以继续。

But what caused the JVM to get into that state? 但是是什么导致JVM进入这种状态呢?

There are a number of possible explanations, but they mostly fall into three classes: 有许多可能的解释,但它们大体分为三类:

  1. Your application has a memory leak. 您的应用程序存在内存泄漏。

  2. Repeated deploys are causing memory to leak. 重复部署导致内存泄漏。

  3. There are no memory leaks, but occasionally your application is getting a request that simply needs too much memory. 没有内存泄漏,但有时您的应用程序收到的请求仅需要太多内存。

Should I restart server between following deploys? 我应该在以下部署之间重新启动服务器吗?

That may help if the deploys are causing the leaks. 如果部署导致泄漏,则可能会有所帮助。 If not, it won't. 如果没有,它不会。

Is there any command to clean heap space? 是否有任何清除堆空间的命令?

There is no command that will do this. 没有命令可以执行此操作。 The JVM will already have run a "full" GC before throwing the OOME. JVM将在抛出OOME之前运行“完整” GC。

If I understand corectly increasing of -Xmx argument will not help. 如果我完全理解-Xmx参数的增加将无济于事。 It will only delay the appearance of the exception. 这只会延迟异常的出现。 Right? 对?

That depends. 那要看。 If the root cause is #3 above, then increasing the heap size may solve the problem. 如果根本原因是上面的#3,那么增加堆大小可以解决此问题。 But if the root cause is #1 or #2, then tweaking the heap size will (at best) cause the JVM to survive longer between crashes. 但是,如果根本原因是#1或#2,那么调整堆大小(最多)将导致JVM在崩溃之间存活的时间更长。


My recommendation is to start by treating this as a "normal" (cause #1) memory leak, and use a memory profiler to identify and fix leaks that are likely to build over time. 我的建议是首先将其视为“正常”(原因1)内存泄漏,并使用内存探查器来识别和修复随时间推移可能累积的泄漏。

If / when you can definitively eliminate cause #1, consider the others. 如果/当您可以明确消除原因1时,请考虑其他原因。

Please increase the MaxPermSize variable and check it will work. 请增加MaxPermSize变量并检查它是否可以工作。

JAVA_OPTS=-Xms1G -Xmx1G -XX:MaxPermSize=512M JAVA_OPTS = -Xms1G -Xmx1G -XX:MaxPermSize = 512M

I absolutely agree with the answer from Stephen C , i just want to show you a possible way how you can analyse it. 我完全同意Stephen C的回答,我只想向您展示一种如何分析它的可能方法。

A minimal tool for monitoring the memory is jstat and comes with JDK . jstatJDK随附的用于监视内存的最小工具。 After starting JBoss you can start monitoring the memory and GC with 启动JBoss之后,您可以使用以下命令开始监视内存和GC

jstat -gc <JBOSS_PID> 2s

The output can then be loaded for example in an excel. 然后可以将输出加载到例如excel中。

Now when you recognize something strange happens with the memory, take a heap dump: 现在,当您发现内存发生奇怪的情况时,请执行堆转储:

jcmd <JBOSS_PID> GC.heap_dump <filename>

jcmd also comes with JDK . jcmd也随JDK

You can than load the heap dump into MAT and analyse it. 然后,您可以将堆转储加载到MAT中并进行分析。 It takes some practice and patience to work with MAT. 使用MAT需要一些实践和耐心。 They also have a good Tutorial . 他们也有一个很好的教程 You can also compare heap dumps in MAT. 您还可以在MAT中比较堆转储。

I also suggest you add XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=<path>" to your JAVA_OPTS. 我还建议您将XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=<path>"到JAVA_OPTS。

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

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