且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Java堆空间--Xmx如何工作?

更新时间:2023-12-03 19:55:58

重新阅读您的错误消息-它可能会告诉您耗尽了哪种类型的内存.我猜这是PermGen空间. Permgen用于类定义(以及其他).您可以通过 -XX:MaxPermSize 调整PermGen的空间,PermGen不属于堆,因此不包含在堆转储中.

Re-read your error message - it may tell you which type of memory you ran out of. I'd guess that it was PermGen space. Permgen is used for class definitions (amongst other things). You can tune the space for PermGen via -XX:MaxPermSize PermGen isn't part of the heap, so isn't included in heap dump.

有关查看PermGen的更多信息,请参见此答案.

See this answer for more information on looking at PermGen.

如果这不是问题,请尝试将初始堆大小(-Xms)设置为与最大堆大小相同.这样做意味着堆不会增长,这将使了解正在发生的事情变得更加容易.

If this isn't the issue, then try setting your initial heap size (-Xms) to the same as the maximum. Doing this means that the heap won't grow which should make understanding what's going on easier.

我建议使用jvisualvm(JDK的一部分)在程序运行时查看您的内存利用率.

I recommend using jvisualvm (part of the JDK) to look at your memory utilisation as your program runs.