Search code examples
javatomcatmemory-leaksout-of-memoryheap-dump

Taking a heap dump on already crashed system


My tomcat application crashed due to memory leak. I want to take the heap dump on the crashed system/jvm. Is it possible? I am using windows/tomcat 6 How?


Solution

  • You can't get a heap dump on a process that is no longer running. Next time you start Tomcat, you're going to have to edit the file in the /bin directory called catalina.sh first so that it contains options to automatically dump the heap if it runs out of memory.

    What you need to do is to edit the JAVA_OPTS variable so that contains the JVM options you need. So near the top of the file, after JAVA_OPTS has been created, you need to do something like

    JAVA_OPTS="$JAVA_OPTS -XX:+HeapDumpOnOutOfMemoryError"

    You can also take heap dumps using JConsole, but in order to do this, you need to know roughly when Tomcat is running out of memory in order for the heap dump to help you diagnose the problem.