Jstack- Stack Trace

Jstack  prints Java Stack traces of java Threads for a given java process or core file or a remote debug server.  For each java frame, the full class name, method name, byte code index and line number, if available are printed.  With the –m option, jstack prints both Java and native frames of all threads along with the program counter.  

Note:  This utility is unsupported and may or may not be available in future versions of the J2SE SDK. Jstack is not currently available on Windows platforms or on the Linux Itanium platform.


jstack [ option ] pid
jstack [ option ] executable core
jstack [ option ] [server-id@]remote-hostname-or-IP

  • pid  process id for which the stack trace is to be printed. The process must be a Java process. To get a list of Java processes running on a machine, jps may be used.
  • executable 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  remote debug server's  hostname or IP address.
  • server-id optional unique id, if multiple debug servers are running on the same remote host.

prints mixed mode (both Java and native C/C++ frames) stack trace.


prints a help message.

prints a help message


Create a very simple Test case called TestSleep.java

class TestSleep {

   public static void main(String[] a) {
      Runtime rt = Runtime.getRuntime();
      System.out.println(" Now Free memory : " + rt.freeMemory());
      System.out.println("And Total memory : " + rt.totalMemory());
      try {Thread.sleep(1000*60*60);} 
      catch (InterruptedException e) {}

Set the java environment and compile and run the class.

D:\KalGyan>javac TestSleep.java

D:\KalGyan>java TestSleep
 Now Free memory : 4952800
And Total memory : 5177344

Open new command prompt and set JDK environment and check for process id and run the jstack

D:\KalGyan>jstack 2292
2011-10-12 09:12:23
Full thread dump Java HotSpot(TM) Client VM (10.0-b19 mixed mode):

"Low Memory Detector" daemon prio=6 tid=0x0aac2800 nid=0x1774 runnable [0x00000000..0x00000000]
   java.lang.Thread.State: RUNNABLE

"CompilerThread0" daemon prio=10 tid=0x0aabcc00 nid=0xc8c waiting on condition [0x00000000..0x0ad0f940]
   java.lang.Thread.State: RUNNABLE

"Attach Listener" daemon prio=10 tid=0x0aabb800 nid=0x12ac waiting on condition [0x00000000..0x00000000]
   java.lang.Thread.State: RUNNABLE

"Signal Dispatcher" daemon prio=10 tid=0x0aabac00 nid=0x1270 runnable [0x00000000..0x00000000]
   java.lang.Thread.State: RUNNABLE

"Finalizer" daemon prio=8 tid=0x0aaab400 nid=0x155c in Object.wait() [0x0ac1f000..0x0ac1fa94]
   java.lang.Thread.State: WAITING (on object monitor)
        at java.lang.Object.wait(Native Method)
        - waiting on <0x02990b38> (a java.lang.ref.ReferenceQueue$Lock)
        at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:116)
        - locked <0x02990b38> (a java.lang.ref.ReferenceQueue$Lock)
        at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:132)
        at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:159)

"Reference Handler" daemon prio=10 tid=0x0aaa7000 nid=0x1314 in Object.wait() [0x0abcf000..0x0abcfb14]
   java.lang.Thread.State: WAITING (on object monitor)
        at java.lang.Object.wait(Native Method)
        - waiting on <0x02990a40> (a java.lang.ref.Reference$Lock)
        at java.lang.Object.wait(Object.java:485)
        at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:116)
        - locked <0x02990a40> (a java.lang.ref.Reference$Lock)

"main" prio=6 tid=0x002a8400 nid=0x179c waiting on condition [0x0090f000..0x0090fe54]
   java.lang.Thread.State: TIMED_WAITING (sleeping)
        at java.lang.Thread.sleep(Native Method)
        at TestSleep.main(TestSleep.java:7)

"VM Thread" prio=10 tid=0x0aaa4000 nid=0x151c runnable

"VM Periodic Task Thread" prio=10 tid=0x0aacc400 nid=0x158c waiting on condition

JNI global references: 582


No comments:

Post a Comment