The jstack tool is used to obtain a stack trace of a running Java process, or optionally from a core file generated if the JVM happens to crash. A stack trace can be extremely valuable when trying to debug a problem, because it provides information about all threads running and exactly what each thread is doing at the point in time that the stack trace was obtained.

Stack traces are helpful when diagnosing problems in which the server appears to be hung or behaving slowly. Java stack traces are generally more helpful than native stack traces, because Java threads can have user-friendly names (as do the threads used by the server), and the frame of the stack trace may include the line number of the source file to which it corresponds. This is useful when diagnosing problems and often allows them to be identified and resolved quickly.

To obtain a stack trace from a running JVM, use the command:

jstack <processID>

Replace <processID> with the process ID of the target JVM as returned by the jps command.

To obtain a stack trace from a core file from a Java process, use the command:

jstack <pathToJava> <pathToCore>

Replace <pathToJava> with the path to the Java command from which the core file was created, and replace <pathToCore> with the path to the core file to examine. In either case, the stack trace is written to standard output and includes the names and call stacks for each of the threads that were active in the JVM.

In many cases, no additional options are necessary. The -l option can be added to obtain a long listing, which includes additional information about locks owned by the threads. The -m option can be used to include native frames in the stack trace.