“Jstack”的版本间的差异
跳到导航
跳到搜索
Jihongchang(讨论 | 贡献) (建立内容为“jstack 用于查看指定 java 进程的线程信息 === 示例 === ==== 代码 ==== <syntaxhighlight lang="java"> public class NewTest { public static void…”的新页面) |
Jihongchang(讨论 | 贡献) (→代码) |
||
第9行: | 第9行: | ||
Thread t = new Thread(); | Thread t = new Thread(); | ||
t.start(); | t.start(); | ||
+ | System.out.printf("id:%d before t.sleep(1000000) ", t.getId()); | ||
t.sleep(1000000); | t.sleep(1000000); | ||
− | System.out. | + | System.out.printf("id:%d after t.sleep(1000000) ", t.getId()); |
t.join(); | t.join(); | ||
System.out.println("after t.join() "); | System.out.println("after t.join() "); | ||
} | } | ||
} | } | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | ==== 控制台 ==== | ||
+ | <syntaxhighlight lang="console"> | ||
+ | id:12 before t.sleep(1000000) | ||
</syntaxhighlight><syntaxhighlight lang="powershell"> | </syntaxhighlight><syntaxhighlight lang="powershell"> | ||
C:\Users\Administrator>jps -lm|findstr NewTest | C:\Users\Administrator>jps -lm|findstr NewTest | ||
− | + | 33712 io.github.jihch.thread.NewTest | |
+ | |||
+ | C:\Users\Administrator>jstack 33712 > NewTest.txt | ||
− | C:\Users\Administrator> | + | C:\Users\Administrator> |
</syntaxhighlight> | </syntaxhighlight> | ||
第29行: | 第37行: | ||
==== NewTest.txt ==== | ==== NewTest.txt ==== | ||
<syntaxhighlight lang="console"> | <syntaxhighlight lang="console"> | ||
− | 2023-02-20 20:37 | + | 2023-02-20 20:44:37 |
Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.101-b13 mixed mode): | Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.101-b13 mixed mode): | ||
− | "Service Thread" #11 daemon prio=9 os_prio=0 tid= | + | "Service Thread" #11 daemon prio=9 os_prio=0 tid=0x000000000a2db800 nid=0x91a4 runnable [0x0000000000000000] |
java.lang.Thread.State: RUNNABLE | java.lang.Thread.State: RUNNABLE | ||
− | "C1 CompilerThread3" #10 daemon prio=9 os_prio=2 tid= | + | "C1 CompilerThread3" #10 daemon prio=9 os_prio=2 tid=0x000000000a2cd800 nid=0x3998 waiting on condition [0x0000000000000000] |
java.lang.Thread.State: RUNNABLE | java.lang.Thread.State: RUNNABLE | ||
− | "C2 CompilerThread2" #9 daemon prio=9 os_prio=2 tid= | + | "C2 CompilerThread2" #9 daemon prio=9 os_prio=2 tid=0x000000000a2cd000 nid=0x8ddc waiting on condition [0x0000000000000000] |
java.lang.Thread.State: RUNNABLE | java.lang.Thread.State: RUNNABLE | ||
− | "C2 CompilerThread1" #8 daemon prio=9 os_prio=2 tid= | + | "C2 CompilerThread1" #8 daemon prio=9 os_prio=2 tid=0x000000000a2cc000 nid=0x9f94 waiting on condition [0x0000000000000000] |
java.lang.Thread.State: RUNNABLE | java.lang.Thread.State: RUNNABLE | ||
− | "C2 CompilerThread0" #7 daemon prio=9 os_prio=2 tid= | + | "C2 CompilerThread0" #7 daemon prio=9 os_prio=2 tid=0x000000000a2c9800 nid=0x9a58 waiting on condition [0x0000000000000000] |
java.lang.Thread.State: RUNNABLE | java.lang.Thread.State: RUNNABLE | ||
− | "Monitor Ctrl-Break" #6 daemon prio=5 os_prio=0 tid= | + | "Monitor Ctrl-Break" #6 daemon prio=5 os_prio=0 tid=0x000000000a2e0800 nid=0x5d38 runnable [0x000000000ab7e000] |
java.lang.Thread.State: RUNNABLE | java.lang.Thread.State: RUNNABLE | ||
at java.net.SocketInputStream.socketRead0(Native Method) | at java.net.SocketInputStream.socketRead0(Native Method) | ||
第56行: | 第64行: | ||
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:326) | at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:326) | ||
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178) | at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178) | ||
− | - locked < | + | - locked <0x0000000715fd22c0> (a java.io.InputStreamReader) |
at java.io.InputStreamReader.read(InputStreamReader.java:184) | at java.io.InputStreamReader.read(InputStreamReader.java:184) | ||
at java.io.BufferedReader.fill(BufferedReader.java:161) | at java.io.BufferedReader.fill(BufferedReader.java:161) | ||
at java.io.BufferedReader.readLine(BufferedReader.java:324) | at java.io.BufferedReader.readLine(BufferedReader.java:324) | ||
− | - locked < | + | - locked <0x0000000715fd22c0> (a java.io.InputStreamReader) |
at java.io.BufferedReader.readLine(BufferedReader.java:389) | at java.io.BufferedReader.readLine(BufferedReader.java:389) | ||
at com.intellij.rt.execution.application.AppMainV2$1.run(AppMainV2.java:49) | at com.intellij.rt.execution.application.AppMainV2$1.run(AppMainV2.java:49) | ||
− | "Attach Listener" #5 daemon prio=5 os_prio=2 tid= | + | "Attach Listener" #5 daemon prio=5 os_prio=2 tid=0x00000000075ee800 nid=0x2eb4 waiting on condition [0x0000000000000000] |
java.lang.Thread.State: RUNNABLE | java.lang.Thread.State: RUNNABLE | ||
− | "Signal Dispatcher" #4 daemon prio=9 os_prio=2 tid= | + | "Signal Dispatcher" #4 daemon prio=9 os_prio=2 tid=0x0000000008ce6800 nid=0x98a0 runnable [0x0000000000000000] |
java.lang.Thread.State: RUNNABLE | java.lang.Thread.State: RUNNABLE | ||
− | "Finalizer" #3 daemon prio=8 os_prio=1 tid= | + | "Finalizer" #3 daemon prio=8 os_prio=1 tid=0x0000000008cc3000 nid=0x8440 in Object.wait() [0x000000000a01e000] |
java.lang.Thread.State: WAITING (on object monitor) | java.lang.Thread.State: WAITING (on object monitor) | ||
at java.lang.Object.wait(Native Method) | at java.lang.Object.wait(Native Method) | ||
第79行: | 第87行: | ||
at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:209) | at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:209) | ||
− | "Reference Handler" #2 daemon prio=10 os_prio=2 tid= | + | "Reference Handler" #2 daemon prio=10 os_prio=2 tid=0x00000000075dc800 nid=0x2ef4 in Object.wait() [0x0000000009f1f000] |
java.lang.Thread.State: WAITING (on object monitor) | java.lang.Thread.State: WAITING (on object monitor) | ||
at java.lang.Object.wait(Native Method) | at java.lang.Object.wait(Native Method) | ||
第88行: | 第96行: | ||
at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:153) | at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:153) | ||
− | "main" #1 prio=5 os_prio=0 tid= | + | "main" #1 prio=5 os_prio=0 tid=0x00000000031e6000 nid=0x3c44 waiting on condition [0x00000000030df000] |
java.lang.Thread.State: TIMED_WAITING (sleeping) | java.lang.Thread.State: TIMED_WAITING (sleeping) | ||
at java.lang.Thread.sleep(Native Method) | at java.lang.Thread.sleep(Native Method) | ||
− | at io.github.jihch.thread.NewTest.main(NewTest.java: | + | at io.github.jihch.thread.NewTest.main(NewTest.java:8) |
− | "VM Thread" os_prio=2 tid= | + | "VM Thread" os_prio=2 tid=0x0000000008ca2800 nid=0x54a0 runnable |
− | "GC task thread#0 (ParallelGC)" os_prio=0 tid= | + | "GC task thread#0 (ParallelGC)" os_prio=0 tid=0x00000000031fb800 nid=0x7bb8 runnable |
− | "GC task thread#1 (ParallelGC)" os_prio=0 tid= | + | "GC task thread#1 (ParallelGC)" os_prio=0 tid=0x00000000031fd000 nid=0x241c runnable |
− | "GC task thread#2 (ParallelGC)" os_prio=0 tid= | + | "GC task thread#2 (ParallelGC)" os_prio=0 tid=0x00000000031fe800 nid=0x89f4 runnable |
− | "GC task thread#3 (ParallelGC)" os_prio=0 tid= | + | "GC task thread#3 (ParallelGC)" os_prio=0 tid=0x0000000003200000 nid=0x2c7c runnable |
− | "GC task thread#4 (ParallelGC)" os_prio=0 tid= | + | "GC task thread#4 (ParallelGC)" os_prio=0 tid=0x0000000003203800 nid=0xcf8 runnable |
− | "GC task thread#5 (ParallelGC)" os_prio=0 tid= | + | "GC task thread#5 (ParallelGC)" os_prio=0 tid=0x0000000003204800 nid=0xaf0 runnable |
− | "GC task thread#6 (ParallelGC)" os_prio=0 tid= | + | "GC task thread#6 (ParallelGC)" os_prio=0 tid=0x0000000003208000 nid=0xc0cc runnable |
− | "GC task thread#7 (ParallelGC)" os_prio=0 tid= | + | "GC task thread#7 (ParallelGC)" os_prio=0 tid=0x0000000003209000 nid=0x9024 runnable |
− | "GC task thread#8 (ParallelGC)" os_prio=0 tid= | + | "GC task thread#8 (ParallelGC)" os_prio=0 tid=0x000000000320a000 nid=0x94f8 runnable |
− | "GC task thread#9 (ParallelGC)" os_prio=0 tid= | + | "GC task thread#9 (ParallelGC)" os_prio=0 tid=0x000000000320b800 nid=0x6a5c runnable |
− | "VM Periodic Task Thread" os_prio=2 tid= | + | "VM Periodic Task Thread" os_prio=2 tid=0x000000000a44c000 nid=0x3a6c waiting on condition |
JNI global references: 16 | JNI global references: 16 |
2023年2月20日 (一) 12:45的最新版本
jstack 用于查看指定 java 进程的线程信息
示例
代码
public class NewTest {
public static void main(String[] args) throws InterruptedException {
Thread t = new Thread();
t.start();
System.out.printf("id:%d before t.sleep(1000000) ", t.getId());
t.sleep(1000000);
System.out.printf("id:%d after t.sleep(1000000) ", t.getId());
t.join();
System.out.println("after t.join() ");
}
}
控制台
id:12 before t.sleep(1000000)
C:\Users\Administrator>jps -lm|findstr NewTest
33712 io.github.jihch.thread.NewTest
C:\Users\Administrator>jstack 33712 > NewTest.txt
C:\Users\Administrator>
NewTest.txt
2023-02-20 20:44:37
Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.101-b13 mixed mode):
"Service Thread" #11 daemon prio=9 os_prio=0 tid=0x000000000a2db800 nid=0x91a4 runnable [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
"C1 CompilerThread3" #10 daemon prio=9 os_prio=2 tid=0x000000000a2cd800 nid=0x3998 waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
"C2 CompilerThread2" #9 daemon prio=9 os_prio=2 tid=0x000000000a2cd000 nid=0x8ddc waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
"C2 CompilerThread1" #8 daemon prio=9 os_prio=2 tid=0x000000000a2cc000 nid=0x9f94 waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
"C2 CompilerThread0" #7 daemon prio=9 os_prio=2 tid=0x000000000a2c9800 nid=0x9a58 waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
"Monitor Ctrl-Break" #6 daemon prio=5 os_prio=0 tid=0x000000000a2e0800 nid=0x5d38 runnable [0x000000000ab7e000]
java.lang.Thread.State: RUNNABLE
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
at java.net.SocketInputStream.read(SocketInputStream.java:170)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:284)
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:326)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178)
- locked <0x0000000715fd22c0> (a java.io.InputStreamReader)
at java.io.InputStreamReader.read(InputStreamReader.java:184)
at java.io.BufferedReader.fill(BufferedReader.java:161)
at java.io.BufferedReader.readLine(BufferedReader.java:324)
- locked <0x0000000715fd22c0> (a java.io.InputStreamReader)
at java.io.BufferedReader.readLine(BufferedReader.java:389)
at com.intellij.rt.execution.application.AppMainV2$1.run(AppMainV2.java:49)
"Attach Listener" #5 daemon prio=5 os_prio=2 tid=0x00000000075ee800 nid=0x2eb4 waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
"Signal Dispatcher" #4 daemon prio=9 os_prio=2 tid=0x0000000008ce6800 nid=0x98a0 runnable [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
"Finalizer" #3 daemon prio=8 os_prio=1 tid=0x0000000008cc3000 nid=0x8440 in Object.wait() [0x000000000a01e000]
java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0x0000000715d08ee0> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:143)
- locked <0x0000000715d08ee0> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:164)
at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:209)
"Reference Handler" #2 daemon prio=10 os_prio=2 tid=0x00000000075dc800 nid=0x2ef4 in Object.wait() [0x0000000009f1f000]
java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0x0000000715d06b50> (a java.lang.ref.Reference$Lock)
at java.lang.Object.wait(Object.java:502)
at java.lang.ref.Reference.tryHandlePending(Reference.java:191)
- locked <0x0000000715d06b50> (a java.lang.ref.Reference$Lock)
at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:153)
"main" #1 prio=5 os_prio=0 tid=0x00000000031e6000 nid=0x3c44 waiting on condition [0x00000000030df000]
java.lang.Thread.State: TIMED_WAITING (sleeping)
at java.lang.Thread.sleep(Native Method)
at io.github.jihch.thread.NewTest.main(NewTest.java:8)
"VM Thread" os_prio=2 tid=0x0000000008ca2800 nid=0x54a0 runnable
"GC task thread#0 (ParallelGC)" os_prio=0 tid=0x00000000031fb800 nid=0x7bb8 runnable
"GC task thread#1 (ParallelGC)" os_prio=0 tid=0x00000000031fd000 nid=0x241c runnable
"GC task thread#2 (ParallelGC)" os_prio=0 tid=0x00000000031fe800 nid=0x89f4 runnable
"GC task thread#3 (ParallelGC)" os_prio=0 tid=0x0000000003200000 nid=0x2c7c runnable
"GC task thread#4 (ParallelGC)" os_prio=0 tid=0x0000000003203800 nid=0xcf8 runnable
"GC task thread#5 (ParallelGC)" os_prio=0 tid=0x0000000003204800 nid=0xaf0 runnable
"GC task thread#6 (ParallelGC)" os_prio=0 tid=0x0000000003208000 nid=0xc0cc runnable
"GC task thread#7 (ParallelGC)" os_prio=0 tid=0x0000000003209000 nid=0x9024 runnable
"GC task thread#8 (ParallelGC)" os_prio=0 tid=0x000000000320a000 nid=0x94f8 runnable
"GC task thread#9 (ParallelGC)" os_prio=0 tid=0x000000000320b800 nid=0x6a5c runnable
"VM Periodic Task Thread" os_prio=2 tid=0x000000000a44c000 nid=0x3a6c waiting on condition
JNI global references: 16