Creating Java thread and/or heap dumps when tomcat freezes or locks up

  • 7020775
  • 17-Mar-2016
  • 07-Aug-2017

Environment


Retain
Windows/Linux
Java/Tomcat

Situation

Tomcat keeps locking up on me.  Retain becomes completely unresponsive.  Is there any helpful information that I can pass onto technical support?

Resolution


Yes, it would help to have the Java threads dumped and/or perform a Java heap dump.   This article provides instructions for both Linux and Windows:

Dump Java Threads - Linux

1.  Get the tomact process' PID:  In a terminal window, type: ps aux |grep tomcat

From the following example, the PID is 3016

2.  Dump the threads.

There are a couple of ways to approach this, so will start with the easiest option and also provide more complicated options (although not too difficult).

a.  Run the following command:  kill -3 [PID] 

This will kill the tomcat process and cause it to dump the threads into the catalina.out file in the Retain logging directory:  

In the example from above, I would type:  kill -3 3016

Because tomcat is not responding, this command will likely fail.   So, don't be surprised if nothing happens.  Move on to step "b".

b.  Run jstack to get a thread dump (note: this option is not available in Retain 4.0.2 or earlier as it required jdk 1.8.0_66 or later): 

Change to the JDK/bin directory: cd /opt/beginfinite/retain/Java8/jdk1.8.0_66/bin  (the java directory name may change with future revisions of Retain, so always verify the directory name first)

Type:  ./jstack -F [PID] > [path/filename]

NOTES:  

1)  The file it dumps the threads to is just a text file by the name you provide in the path you specify, so you may want to give the filename a "txt" or "log" extension so it can be opened into a text editor easily.

2)  Because you are likely asked to perform this task by Support, tomcat (Retain) is likely locking up or the server is becoming very unresponsive.  For this reason, you should have the command window open and the command line typed out in advance so all you have to do is press the ENTER key to start it when the server becomes sluggish.

Java Heap Dump - Linux

Run jmap to get a Java heap dump:  

1.  Get the PID for tomcat (see step #1 "Dump Java Threads").

2.  Change to the JDK/bin directory: cd /opt/beginfinite/retain/Java8/jdk1.8.0_66/bin  (the java directory name may change with future revisions of Retain, so always verify the directory name first)

3.  Excecute jmap as follows:   jmap -dump:format=b,file=[/path]/heap.bin [PID]

Depending on how much Java heap is configured and used, the resulting file could be up 13 GB or more and it will take a while to complete.  So, be sure to supply a path to a volume that has plenty of available disk space.
 

Dump Java Threads - Windows

1.  In task manager, get the PID for Java/tomcat.  In this case, the PID is 4076.

2.  Open a command window

3.  Change to the JDK/bin directory: [drive]:\Program Files\Beginfinite\Retain\Java8\jdk1.8.0_66\bin (the java directory name may change with future revisions of Retain, so always verify the directory name first)

4.  Type:  jstack [PID] > [filename]

NOTE:  The file it dumps the threads to is just a text file by the name you provide in the path you specify, so you may want to give the filename a "txt" extension so it can be opened into a text editor easily.


There is a strong likelihood that this first attempt will fail, telling you that the process is not responding and to try the "-F" option.  In such cases, run the command with that option as follows:

jstack -F [PID] > [filename]

5.  Now you can stop tomcat or reboot the server.

Java Heap Dump - Windows

Run jmap to get a Java heap dump:  

1.  Get the PID for tomcat (see step #1 "Dump Java Threads").

2.  Change to the JDK/bin directory in a command window: [drive]:\Program Files\Beginfinite/Retain/Java8/jdk1.8.0_66/bin  (the java directory name may change with future revisions of Retain, so always verify the directory name first)

3.  Excecute jmap as follows:   jmap -dump:format=b,file=[/path]/heap.bin [PID]

Depending on how much Java heap is configured and used, the resulting file could be up 13 GB or more and it will take a while to complete.  So, be sure to supply a path to a volume that has plenty of available disk space.

Additional Information

This article was originally published in the GWAVA knowledgebase as article ID 2771.