The jstack is used to print out the Java stack information for a given Java process ID or core file or remote Debugging service.
If you need to specify the option "-j-d64" on a 64-bit machine, the Jstack usage of Windows only supports this way: jstack [-l] PID
If a Java program crashes generating a core file, the Jstack tool can be used to obtain information about the core file's Java stack and the native stack, making it easy to know how the Java program crashes and where the problem occurs in the program.
In addition, the Jstack tool can be attached to a running Java program to see the Java stack and the native stack of the Java program that was running, and jstack is useful if the Java program that is running now renders hung state.
Issues to be aware of:
L different Java Virtual machine thread dump creation method and file format is not the same, different JVM version, dump information also differs.
L in the actual operation, often a dump of information, not enough to confirm the problem. It is recommended to generate three dump messages, and if each dump points to the same problem, we determine the typical problem.
2. Command format
$jstack [option] pid
$jstack [option] executable core
$jstack [option] [[Email Protected]]remote-hostname-or-ip
Parameter description:
The process number of the Pid:java application can be obtained by JPS;
Executable: Java executable program that produces core dump;
Core: Print out the core file;
REMOTE-HOSTNAME-OR-IP: Name or IP of the remote debug server;
Server-id: Unique ID, if there are multiple remote debug services on a single host;
Example:
$jstack –l 23561
Threading Analysis:
In general, the thread information output through Jstack mainly includes: JVM itself thread, user thread, etc. Where the JVM thread will be present when the JVM is started. The user thread is generated when the user accesses it.
L JVM Thread:
In the thread, there are background threads inside the JVM that perform tasks such as garbage collection, or low memory detection, which are often present when the JVM is initialized, as follows:
1"Attach Listener" daemon prio=10 tid=0x0000000052fb8000 nid=0xb8f waiting on condition [0x0000000000000000]2 3 Java.lang.Thread.State:RUNNABLE4 5 6 7 Locked ownable synchronizers:8 9-NoneTen OneDESTROYJAVAVM "prio=10 tid=0x00002aaac1225800 nid=0x7208 waiting on condition [0x0000000000000000] A - Java.lang.Thread.State:RUNNABLE - the - - Locked ownable synchronizers: - +-None
L User-level threads
There is also a class of threads that are user-level and vary depending on the user's request. The running of this kind of thread is often the focus of our attention. And this part is the easiest place to create a deadlock.
1"Qtp496432309-42" prio=10 tid=0x00002aaaba2a1800 nid=0x7580 waiting on condition [0x00000000425e9000]2 3 Java.lang.Thread.State:TIMED_WAITING (parking)4 5 At Sun.misc.Unsafe.park (Native Method)6 7-Parking to wait for<0x0000000788cfb020>(a java.util.concurrent.locks.abstractqueuedsynchronizer$conditionobject)8 9At Java.util.concurrent.locks.LockSupport.parkNanos (locksupport.java:198)Ten OneAt Java.util.concurrent.locks.abstractqueuedsynchronizer$conditionobject.awaitnanos ( abstractqueuedsynchronizer.java:2025) A -At Org.eclipse.jetty.util.BlockingArrayQueue.poll (blockingarrayqueue.java:320) - theAt Org.eclipse.jetty.util.thread.queuedthreadpool$2.run (queuedthreadpool.java:479) - -At Java.lang.Thread.run (thread.java:662) - + - + Locked ownable synchronizers: A at-None
From the code example above, we can see the following types of information about the user thread:
Ø thread Status: Waiting on condition (wait condition occurs)
Ø the invocation of the thread;
Ø thread-to-resource locking situation;
Linux jstack Command Detailed