2

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

Petro Semeniuk
  • 6,970
  • 10
  • 42
  • 65
  • You can use VisualVM to do a HeapDump, newer Java versions have it on board, look into bin/ folder. – Jens Peters Mar 03 '13 at 23:04
  • In Unix, SIGQUIT (whether sent with a kill command or by typing Ctrl-\ in the program's console) will dump all threads' stack traces. In Windows, Ctrl-Break in the program's console will do it. – VGR Mar 03 '13 at 23:10

1 Answers1

4

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

Community
  • 1
  • 1
zagyi
  • 17,223
  • 4
  • 51
  • 48