简体   繁体   English

实际上有可用内存时,Java内存不足错误

[英]Java out of memory error when memory is in fact available

I keep running into OOM errors and subsequent JBoss crashes, even though the heap shows that all of the memory allocated to it isn't used up. 即使堆显示分配给它的所有内存都没有用完,我仍会遇到OOM错误并随后导致JBoss崩溃。

For eg: If I have 1200MB allocated as the heap size (Xmx), crashes occur well below that limit with none of the individual generations in the heap (young / old / perm) at a 100%. 例如:如果我分配了1200MB作为堆大小(Xmx),则崩溃发生在远低于该限制的范围内,堆中的各个世代(年轻/旧/烫发)都没有达到100%。

The box has plenty of RAM. 盒子有足够的内存。 Why might java be reporting this error when its really not out of memory? 为什么Java确实没有内存不足时会报告此错误?

 Heap

 PSYoungGen      total 67456K, used 9525K [0x57540000, 0x5c170000, 0x5fa90000)
  eden space 66432K, 12% used [0x57540000,0x57d91520,0x5b620000)
  from space 1024K, 98% used [0x5c070000,0x5c16c198,0x5c170000)
  to   space 3008K, 0% used [0x5bb90000,0x5bb90000,0x5be80000)

 PSOldGen        total 466048K, used 313530K [0x14a90000, 0x311b0000, 0x57540000)
  object space 466048K, 67% used [0x14a90000,0x27cbea38,0x311b0000)

 PSPermGen       total 226432K, used 141461K [0x04a90000, 0x127b0000, 0x14a90000)
  object space 226432K, 62% used [0x04a90000,0x0d4b55e8,0x127b0000)

Yes it is possible to get an OOME when you've still got plenty of free heap space. 是的,当您仍然有足够的可用堆空间时,可以获得OOME。

When you create a thread the JVM needs to allocate memory for the thread's stack. 创建线程时,JVM需要为线程的堆栈分配内存。 However the JVM doesn't allocate the thread stack in the heap. 但是,JVM不会在堆中分配线程堆栈。 (The thread stack needs to be in memory that won't be moved by the garbage collector.) Instead, it requests it directly from the OS. (线程堆栈必须位于内存中,垃圾回收器不会移动它。)相反,它直接从OS请求它。 If the OS can't satisfy that request, you get an OOME ... irrespective of your heap size. 如果操作系统不能满足该请求,则无论堆大小如何,您都会得到一个OOME...。

Apparently, an OOME can also occur during thread creation if your application exceeds the operating system's per-process thread limit. 显然,如果您的应用程序超出了操作系统的每进程线程限制,则在线程创建期间也会发生OOME。 (On Linux / Unix this is controlled by ulimit -u ...) (在Linux / Unix上,这由ulimit -u ...控制)


It is a bit difficult to say what is happening in your case. 很难说出您的情况。 I suspect that your application is simply trying to create too many threads and running into one of the limitations above. 我怀疑您的应用程序只是试图创建太多线程而遇到上述限制之一。 You could try reducing the thread stack size, but a better approach would be to figure out why you are creating so many threads and stop it. 您可以尝试减小线程堆栈的大小,但是更好的方法是弄清楚为什么创建这么多线程并停止它。 (Huge numbers of threads tend to waste resources ... and make your application slower in various ways.) (大量线程往往会浪费资源……并以各种方式使您的应用程序变慢。)

在JBoss社区网站上查看此答案 ,以了解为什么您将无法创建新线程OOM

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

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