Currently, many applications are using JVM for processing, the active process are divided into various java threads. The list of java threads that are currently active in the JVM is called as thread dump. Sometimes we are faced with a condition where the java thread is running not as it should be, then checks are needed for investigation. To check for java threads needed tools. There are several ways to take thread dumps from a JVM.
For our case, we will use jstack with Solaris 10 environment as our case test. Here's how to take thread dump with jstack in a Solaris 10 environment.
1. List the PID of all active java processes
[joe01@testbed01]$ uname -a
SunOS utest01 5.10 Generic_150400-30 sun4v sparc SUNW,SPARC-Enterprise-T5220
[joe01@testbed01 ]$ ps -ef| grep java
stystem 3498 3469 0 Sep 26 ? 550:55 /usr/jre1.6.0_07/bin/java -Dprogram.name=run.sh -server -Xms256m -Xmx3072m -XX:
stystem 26440 1 0 Oct 05 ? 98:35 /app/st/jdk1.6.0_12/bin/java -server -Xmx1020M -XX:TargetSurvivorRatio=90 -X
stystem 24938 24919 0 20:56:18 pts/5 0:00 grep java
stystem 7233 1 0 Oct 05 ? 100:47 /app/st/jdk1.6.0_12/bin/java -server -Xmx1020M -XX:TargetSurvivorRatio=90 -X
stystem 2073 1 0 Oct 05 ? 26:10 /app/st/jdk1.6.0_12/bin/java -server -Xmx1020M -XX:TargetSurvivorRatio=90 -X
stystem 2842 1 0 Oct 05 ? 75:55 /app/st/jdk1.6.0_12/bin/java -server -Xmx1020M -XX:TargetSurvivorRatio=90 -X
stystem 1284 1 0 Oct 05 ? 85:36 /app/st/jdk1.6.0_12/bin/java -server -Xmx1020M -XX:TargetSurvivorRatio=90 -X
stystem 28953 1 0 Oct 05 ? 179:41 /app/st/jdk1.6.0_12/bin/java -Djava.security.properties=/app/st/jre1.7.0_
2. Run the jstack to request thread dump from the JVM. The command line will be jstack -l
[joe01@testbed01]pwd
/app/rapcorp/jdk1.6.0_12/bin
[joe01@testbed01]$ ls -ltr jstack
-rwxr-xr-x 1 rapcorpadm rapcorp 47788 Apr 28 2016 jstack
[joe01@testbed01]$ ./jstack -h
Usage:
jstack [-l]
(to connect to running process)
jstack -F [-m] [-l]
(to connect to a hung process)
jstack [-m] [-l]
(to connect to a core file)
jstack [-m] [-l] [server_id@]
(to connect to a remote debug server)
Options:
-F to force a thread dump. Use when jstack 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
[joe01@testbed01]$ ./jstack -l 26440| more
2017-10-25 15:50:37
Full thread dump Java HotSpot(TM) Server VM (11.2-b01 mixed mode):
"Attach Listener" daemon prio=3 tid=0x00afb400 nid=0x718d waiting on condition [0x00000000..0x00000000]
java.lang.Thread.State: RUNNABLE
[joe01@testbed01]$ ./jstack -F 25468
ttaching to process ID 25468, please wait...
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at sun.tools.jstack.JStack.runJStackTool(JStack.java:118)
at sun.tools.jstack.JStack.main(JStack.java:84)
Caused by: java.lang.RuntimeException: Type "nmethodBucket*", referenced in VMStructs::localHotSpotVMStructs in the remote VM, was not present in the remote VMStructs::localHotSpotVMTypes table (should have been caught in the debug build of that VM). Can not continue.
at sun.jvm.hotspot.HotSpotTypeDataBase.lookupOrFail(HotSpotTypeDataBase.java:361)
at sun.jvm.hotspot.HotSpotTypeDataBase.readVMStructs(HotSpotTypeDataBase.java:252)
at sun.jvm.hotspot.HotSpotTypeDataBase.(HotSpotTypeDataBase.java:87)
at sun.jvm.hotspot.bugspot.BugSpotAgent.setupVM(BugSpotAgent.java:562)
at sun.jvm.hotspot.bugspot.BugSpotAgent.go(BugSpotAgent.java:494)
at sun.jvm.hotspot.bugspot.BugSpotAgent.attach(BugSpotAgent.java:332)
For convenion way, we throw the result to a file.
For our case, we will use jstack with Solaris 10 environment as our case test. Here's how to take thread dump with jstack in a Solaris 10 environment.
1. List the PID of all active java processes
[joe01@testbed01]$ uname -a
SunOS utest01 5.10 Generic_150400-30 sun4v sparc SUNW,SPARC-Enterprise-T5220
[joe01@testbed01 ]$ ps -ef| grep java
stystem 3498 3469 0 Sep 26 ? 550:55 /usr/jre1.6.0_07/bin/java -Dprogram.name=run.sh -server -Xms256m -Xmx3072m -XX:
stystem 26440 1 0 Oct 05 ? 98:35 /app/st/jdk1.6.0_12/bin/java -server -Xmx1020M -XX:TargetSurvivorRatio=90 -X
stystem 24938 24919 0 20:56:18 pts/5 0:00 grep java
stystem 7233 1 0 Oct 05 ? 100:47 /app/st/jdk1.6.0_12/bin/java -server -Xmx1020M -XX:TargetSurvivorRatio=90 -X
stystem 2073 1 0 Oct 05 ? 26:10 /app/st/jdk1.6.0_12/bin/java -server -Xmx1020M -XX:TargetSurvivorRatio=90 -X
stystem 2842 1 0 Oct 05 ? 75:55 /app/st/jdk1.6.0_12/bin/java -server -Xmx1020M -XX:TargetSurvivorRatio=90 -X
stystem 1284 1 0 Oct 05 ? 85:36 /app/st/jdk1.6.0_12/bin/java -server -Xmx1020M -XX:TargetSurvivorRatio=90 -X
stystem 28953 1 0 Oct 05 ? 179:41 /app/st/jdk1.6.0_12/bin/java -Djava.security.properties=/app/st/jre1.7.0_
2. Run the jstack to request thread dump from the JVM. The command line will be jstack -l
[joe01@testbed01]pwd
/app/rapcorp/jdk1.6.0_12/bin
[joe01@testbed01]$ ls -ltr jstack
-rwxr-xr-x 1 rapcorpadm rapcorp 47788 Apr 28 2016 jstack
[joe01@testbed01]$ ./jstack -h
Usage:
jstack [-l]
(to connect to running process)
jstack -F [-m] [-l]
(to connect to a hung process)
jstack [-m] [-l]
(to connect to a core file)
jstack [-m] [-l] [server_id@]
(to connect to a remote debug server)
Options:
-F to force a thread dump. Use when jstack
-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
[joe01@testbed01]$ ./jstack -l 26440| more
2017-10-25 15:50:37
Full thread dump Java HotSpot(TM) Server VM (11.2-b01 mixed mode):
"Attach Listener" daemon prio=3 tid=0x00afb400 nid=0x718d waiting on condition [0x00000000..0x00000000]
java.lang.Thread.State: RUNNABLE
[joe01@testbed01]$ ./jstack -F 25468
ttaching to process ID 25468, please wait...
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at sun.tools.jstack.JStack.runJStackTool(JStack.java:118)
at sun.tools.jstack.JStack.main(JStack.java:84)
Caused by: java.lang.RuntimeException: Type "nmethodBucket*", referenced in VMStructs::localHotSpotVMStructs in the remote VM, was not present in the remote VMStructs::localHotSpotVMTypes table (should have been caught in the debug build of that VM). Can not continue.
at sun.jvm.hotspot.HotSpotTypeDataBase.lookupOrFail(HotSpotTypeDataBase.java:361)
at sun.jvm.hotspot.HotSpotTypeDataBase.readVMStructs(HotSpotTypeDataBase.java:252)
at sun.jvm.hotspot.HotSpotTypeDataBase.
at sun.jvm.hotspot.bugspot.BugSpotAgent.setupVM(BugSpotAgent.java:562)
at sun.jvm.hotspot.bugspot.BugSpotAgent.go(BugSpotAgent.java:494)
at sun.jvm.hotspot.bugspot.BugSpotAgent.attach(BugSpotAgent.java:332)