jstack definition:
jstack is a stack trace tool that comes with Java virtual machines.
Basic introduction:
jstack is used to generate a thread snapshot of the current time of the java virtual machine. Thread snapshots are a collection of method stacks that each thread in the current Java virtual machine is executing. The main purpose of generating thread snapshots is to locate the reasons for long-term pauses of threads, such as deadlocks between threads, dead loops, and long-term waiting caused by requesting external resources.
When a thread pauses, you can check the call stack of each thread through jstack, and you can know what the unresponsive thread is doing in the background or what resources it is waiting for.
Command format:
jstack [ option ] pid
Basic parameters:
-F Force printing stack information when 'jstack [-l] pid' does not have corresponding
-l Long list. Print additional information about the lock, such as the ownable synchronizer list belonging to java.util.concurrent.
-m Print all stack information of java and native c/c++ frameworks. -h | -help Print help information
pid java process id that needs to be printed configuration information, you can use the jps tool to query
Case
C:/Users/Administrator>jstack 5516Full thread dump Java HotSpot(TM) 64-Bit Server VM (24.79-b02 mixed mode): "DestroyJavaVM" prio=6 tid=0x00000000000027d800 nid=0x1bb0 waiting on condition [0x0000000000000000] java.lang.Thread.State: RUNNABLE "Thread-1" prio=6 tid=0x00000000000cb13800 nid=0x19ac waiting for monitor entry [0x0000000000d67f000] java.lang.Thread.State: BLOCKED (on object monitor) at thread.DeadLockDemo$2.run(DeadLockDemo.java:35) - waiting to lock <0x00000007d5a9be88> (a java.lang.String) - locked <0x00000007d5a9beb8> (a java.lang.String) at java.lang.Thread.run(Unknown Source) "Thread-0" prio=6 tid=0x000000000cb0e800 nid=0x6bc waiting for monitor entry [0x000000000d48f000] java.lang.Thread.State: BLOCKED (on object monitor) at thread.DeadLockDemo$1.run(DeadLockDemo.java:21) - waiting to lock <0x00000007d5a9beb8> (a java.lang.String) - locked <0x00000007d5a9be88> (a java.lang.String) at java.lang.Thread.run(Unknown Source)
A deadlock code is run here, causing both threads in the program to wait for the other party to release the lock, causing the program to be deadlocked.
From this code, it can be clearly seen that line 35 and line 21 in DeadLockDemo.class are blocked, and then we need to optimize this function.
PS: In actual operation, the dump information is often not enough to confirm the problem. It is recommended to generate three dump information. If each dump points to the same problem, we will determine the typicality of the problem.
Summarize
The above is all about the analysis of jstack and thread dump instances in this article. I hope it will be helpful to everyone. Interested friends can continue to refer to other related topics on this site. If there are any shortcomings, please leave a message to point it out. Thank you friends for your support for this site!