“Jstack”的版本间的差异

来自姬鸿昌的知识库
跳到导航 跳到搜索
(建立内容为“jstack 用于查看指定 java 进程的线程信息 === 示例 === ==== 代码 ==== <syntaxhighlight lang="java"> public class NewTest { public static void…”的新页面)
 
 
第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.println("after t.sleep(1000000) ");
+
         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
33392 io.github.jihch.thread.NewTest
+
33712 io.github.jihch.thread.NewTest
 +
 
 +
C:\Users\Administrator>jstack 33712 > NewTest.txt
  
C:\Users\Administrator>jstack 33392 > NewTest.txt
+
C:\Users\Administrator>
 
</syntaxhighlight>
 
</syntaxhighlight>
  
第29行: 第37行:
 
==== NewTest.txt ====
 
==== NewTest.txt ====
 
<syntaxhighlight lang="console">
 
<syntaxhighlight lang="console">
2023-02-20 20:37:27
+
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=0x000000000a92f000 nid=0x410c runnable [0x0000000000000000]
+
"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=0x000000000a925800 nid=0x93a4 waiting on condition [0x0000000000000000]
+
"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=0x000000000a924800 nid=0x77e4 waiting on condition [0x0000000000000000]
+
"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=0x000000000a924000 nid=0x8fcc waiting on condition [0x0000000000000000]
+
"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=0x000000000a921000 nid=0x84dc waiting on condition [0x0000000000000000]
+
"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=0x000000000a941800 nid=0x558c runnable [0x000000000b1de000]
+
"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 <0x0000000715fd2660> (a java.io.InputStreamReader)
+
- 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 <0x0000000715fd2660> (a java.io.InputStreamReader)
+
- 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=0x00000000093fb800 nid=0xbc80 waiting on condition [0x0000000000000000]
+
"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=0x00000000093a6800 nid=0x3c28 runnable [0x0000000000000000]
+
"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=0x0000000009383000 nid=0x3710 in Object.wait() [0x000000000a6df000]
+
"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=0x0000000007cac800 nid=0x5e50 in Object.wait() [0x000000000a5df000]
+
"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=0x00000000038b6000 nid=0x7c70 waiting on condition [0x00000000036af000]
+
"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:7)
+
at io.github.jihch.thread.NewTest.main(NewTest.java:8)
  
"VM Thread" os_prio=2 tid=0x0000000009362800 nid=0x92e0 runnable  
+
"VM Thread" os_prio=2 tid=0x0000000008ca2800 nid=0x54a0 runnable  
  
"GC task thread#0 (ParallelGC)" os_prio=0 tid=0x00000000038cb800 nid=0xb220 runnable  
+
"GC task thread#0 (ParallelGC)" os_prio=0 tid=0x00000000031fb800 nid=0x7bb8 runnable  
  
"GC task thread#1 (ParallelGC)" os_prio=0 tid=0x00000000038cd000 nid=0x95cc runnable  
+
"GC task thread#1 (ParallelGC)" os_prio=0 tid=0x00000000031fd000 nid=0x241c runnable  
  
"GC task thread#2 (ParallelGC)" os_prio=0 tid=0x00000000038ce800 nid=0x195c runnable  
+
"GC task thread#2 (ParallelGC)" os_prio=0 tid=0x00000000031fe800 nid=0x89f4 runnable  
  
"GC task thread#3 (ParallelGC)" os_prio=0 tid=0x00000000038d0000 nid=0x99c8 runnable  
+
"GC task thread#3 (ParallelGC)" os_prio=0 tid=0x0000000003200000 nid=0x2c7c runnable  
  
"GC task thread#4 (ParallelGC)" os_prio=0 tid=0x00000000038d3800 nid=0x96f0 runnable  
+
"GC task thread#4 (ParallelGC)" os_prio=0 tid=0x0000000003203800 nid=0xcf8 runnable  
  
"GC task thread#5 (ParallelGC)" os_prio=0 tid=0x00000000038d4800 nid=0x7018 runnable  
+
"GC task thread#5 (ParallelGC)" os_prio=0 tid=0x0000000003204800 nid=0xaf0 runnable  
  
"GC task thread#6 (ParallelGC)" os_prio=0 tid=0x00000000038d8000 nid=0x73b0 runnable  
+
"GC task thread#6 (ParallelGC)" os_prio=0 tid=0x0000000003208000 nid=0xc0cc runnable  
  
"GC task thread#7 (ParallelGC)" os_prio=0 tid=0x00000000038d9000 nid=0x1270 runnable  
+
"GC task thread#7 (ParallelGC)" os_prio=0 tid=0x0000000003209000 nid=0x9024 runnable  
  
"GC task thread#8 (ParallelGC)" os_prio=0 tid=0x00000000038da000 nid=0x282c runnable  
+
"GC task thread#8 (ParallelGC)" os_prio=0 tid=0x000000000320a000 nid=0x94f8 runnable  
  
"GC task thread#9 (ParallelGC)" os_prio=0 tid=0x00000000038db800 nid=0x8634 runnable  
+
"GC task thread#9 (ParallelGC)" os_prio=0 tid=0x000000000320b800 nid=0x6a5c runnable  
  
"VM Periodic Task Thread" os_prio=2 tid=0x000000000aa8c000 nid=0x83d0 waiting on condition  
+
"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