How-to: Obtain Thread Dump and Heap Dump on JBoss/WildFly

Sometimes you need to analyze unexpected behavior on application server. Out of memory, EJB pool exhaustion or deadlock are one of many problems with which you can often met. And not always the server log will help you. When log is empty, but application shows signs of errors (is slow or maybe even stuck) you need to obtain the maximum amount of information and backup the current state of the whole JVM for later analysis. If reboot is your only action, you will lose all the information that might reveal the source of error and problem may soon reoccur again (and most likely during holidays).

Thread Dump

Creates a listing of the current state of all threads within JVM. It’s advisable to do this listing repeatedly (in differently named outputs, don’t overwrite your dumps) within a few tens of seconds. This allows you to capture changes and possible dead-lock. If nothing has changed and thread is on the same row, then there might be a problem.

So how to do it:

Open the console (CMD), switch to “/Java/jdkx.x.x_xx /bin” (JDK) using the “cd” command. Then type “jstack JVM_PID > C:/Users/Administrator/Desktop/thread_dump_1“. Replace the “JVM_PID” with the process ID of running JVM (Task Manager – Details – PID column). Be careful and take the correct PID. If another JVM is running on the server, such as JVM for VisualVM, it also has a custom process for JVM with a similar name. You can replace them by mistake.

Heap Dump

Creates a byte copy of JVM heap. Byte copy has same size as an allocated space for heap. You need to have enough space on the server as you can kill the whole server due to lack of disk space.

So how to do it:

Open the console (CMD), switch to “/Java/jdkx.x.x_xx /bin” (JDK) using the “cd” command. Then type “jmap.exe -dump: format = b, file = C:/Users/Administrator/Desktop/heapdump.hprof JVM_PID“. Replace the “JVM_PID” with the process ID of running JVM (Task Manager – Details – PID column). Again, beware and take the correct PID.

Thread Dump usually takes a few seconds to create, but the heap dump may take several minutes depending on the amount of allocated space for heap.

Leave a Reply

Your email address will not be published. Required fields are marked *