In this article we are going to see the jstack commands.

What is jstack?

jstack prints Java stack traces of Java threads for a Java process /core file /a remote debug server.


jstack [ option ] pId
jstack [ option ] exe core
jstack [ option ] [server-id@]remote-hostname-or-IP 

In here :

  • pId = Java process id (use jps to get the info)
  • exe = Java executable from which the core dump was produced.
  • core = core file for which the stack trace is to be printed.
  • remote-hostname-or-IP = Debug server’s (see jsadebugd) hostname or IP address.
  • server-id= (optional) unique server id

jstack Options :

  • F : Force a stack dump when ‘jstack (-l) pid’ is not responsive.
  • l : Long listing. (Prints more info about locks)
  • m : Prints mixed mode (both Java and C/C++ frames) stack trace.

From CLI

        jstack [-l] <pid>
            (to connect to running process)
        jstack -F [-m] [-l] <pid>
            (to connect to a hung process)
        jstack [-m] [-l] <executable> <core>
            (to connect to a core file)
        jstack [-m] [-l] [server_id@]<remote server IP or hostname>
            (to connect to a remote debug server)
        -F  to force a thread dump. Use when jstack <pid> does not respond (process is hung)
        -m  to print both java and native frames (mixed mode)
        -l  long listing. Prints additional information about locks
        -h or -help to print this help message

Notes :

  • If the given process is running on a 64-bit VM, we need to specify the -J-d64 option.
  • In windows, the system path variable should contain jvm.dll (for my pc, it is in C:\Program Files\Java\jre6\bin\server).