如何在内存不足错误时执行线程转储 [英] How to do thread dump on Out Of Memory Error

查看:78
本文介绍了如何在内存不足错误时执行线程转储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道-XX:+HeapDumpOnOutOfMemoryError将在OutOfMemoryError上启用堆转储.

I know that -XX:+HeapDumpOnOutOfMemoryError will enable heap dump on OutOfMemoryError.

是否有类似的线程转储?如果服务器上发生错误,我就需要这样做-发生错误时,我无权访问流程本身

Is there anything similar for thread dump? I need this in case when error happens on server - I don't have access to process itself when it happens

推荐答案

引发OutOfMemoryError的确切执行点是非常随机的(除非您有单个线程应用程序),所以我认为这样做不会在OOM上获得线程转储的意义太大.至少如果是"Java堆空间"类型的OOM,这是正确的,但也可能是其他类型的OOM错误.

The exact point of execution where an OutOfMemoryError is raised is very much random (unless you have a single threaded application), so I don't think it would make too much sense to get a thread dump upon OOM. At least this is true if it's the 'Java heap space' sort of OOM, but probably for the other sorts of OOM errors as well.

无论如何,请看这篇较旧的帖子针对同一问题.

Anyway, take a look at this older post addressing the same question.

解决OOM错误的更好方法是使用 Eclipse内存分析器工具来检查堆转储.通过将对象图转换成所谓的浅堆与保留堆).

However a better way to tackle an OOM error is to use the Eclipse Memory Analyzer Tool to inspect the heapdump. It helps you to identify memory leaks by transforming the object graph into a so-called dominator tree. This structure reveals the keep-alive dependencies among objects, so it becomes very easy to identify the ones responsible for retaining the biggest chunks of memory (see Shallow vs. Retained Heap).

这篇关于如何在内存不足错误时执行线程转储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆