How to do thread dump on Out Of Memory Error [duplicate]

我的梦境 提交于 2019-12-08 02:41:15

问题


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


回答1:


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.

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).



来源:https://stackoverflow.com/questions/15191999/how-to-do-thread-dump-on-out-of-memory-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!