thread
查看线程、线程堆栈信息
命令选项
命令选项 | 描述 |
---|---|
--all | 查看所有线程 |
-b, --include-blocking-thread | 查看死锁线程 |
--lockedMonitors | 包含监视器锁(synchronized)信息 |
--lockedSynchronizers | 包含ReentrantLock和ReentrantReadWriteLock锁信息 |
-i, --sample-interval <number> | 刷新cpu频率(ms) |
--state <value> | 查看指定线程状态的线程 |
-n, --top-n-threads <number> | 根据cpu排序,查看前n根线程堆栈 |
-h, --help | 帮助 |
<id> | 查看指定线程id的堆栈 |
列描述说明
参考dashboard中THREAD部分说明
列名 | 说明 |
---|---|
ID | 线程id |
NAME | 线程名 |
GROUP | 现场组名 |
PRIORITY | 优先级 |
STATE | 线程状态 |
%CPU | CPU占用率 |
DELTA_TIME | 上次采样之后线程运行增量CPU时间,数据单位秒 |
TIME | 线程运行总CPU时间,格式分:秒 |
INTERRUPTED | 线程当前的中断位状态 |
DAEMON | 是否守护线程 |
线程状态
- RUNNABLE
- BLOCKED
- WAITING
- TIMED_WAITING
- NEW
- TERMINATED
示例
bash
# 查看所有线程
[arthas@10580]$ thread
2 Reference Handler system 10 WAITING 0.0 0.000 0:0.000 false true
3 Finalizer system 8 WAITING 0.0 0.000 0:0.031 false true
4 Signal Dispatcher system 9 RUNNABLE 0.0 0.000 0:0.000 false true
5 Attach Listener system 5 RUNNABLE 0.0 0.000 0:0.031 false true
...
1 main main 5 TIMED_WAITING 0.0 0.000 0:0.390 false false
25 RMI TCP Connection(1)-127.0.0.1 RMI Runtime 5 RUNNABLE 0.0 0.000 0:0.328 false true
99 RMI TCP Connection(367)-127.0.0.1 RMI Runtime 5 RUNNABLE 0.0 0.000 0:0.203 false true
104 RMI TCP Connection(366)-127.0.0.1 RMI Runtime 5 RUNNABLE 0.0 0.000 0:0.046 false true
# 查看指定状态的线程
[arthas@10580]$ thread --state RUNNABLE
# 查看阻塞线程堆栈
[arthas@10580]$ thread -b
No most blocking thread found!
# 查看占用cpu前N线程
[arthas@10580]$ thread -n 5
"Reference Handler" Id=2 cpuUsage=0.0% deltaTime=0ms time=0ms WAITING on java.lang.ref.Reference$Lock@7e15a0e0
at java.lang.Object.wait(Native Method)
- waiting on java.lang.ref.Reference$Lock@7e15a0e0
at java.lang.Object.wait(Object.java:502)
at java.lang.ref.Reference.tryHandlePending(Reference.java:191)
at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:153)
"Finalizer" Id=3 cpuUsage=0.0% deltaTime=0ms time=31ms WAITING on java.lang.ref.ReferenceQueue$Lock@1b520acc
at java.lang.Object.wait(Native Method)
- waiting on java.lang.ref.ReferenceQueue$Lock@1b520acc
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:144)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:165)
at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:216)
"Signal Dispatcher" Id=4 cpuUsage=0.0% deltaTime=0ms time=0ms RUNNABLE
"Attach Listener" Id=5 cpuUsage=0.0% deltaTime=0ms time=31ms RUNNABLE
"RMI TCP Accept-26648" Id=21 cpuUsage=0.0% deltaTime=0ms time=0ms RUNNABLE (in native)
at java.net.DualStackPlainSocketImpl.accept0(Native Method)
at java.net.DualStackPlainSocketImpl.socketAccept(DualStackPlainSocketImpl.java:131)
at java.net.AbstractPlainSocketImpl.accept(AbstractPlainSocketImpl.java:409)
at java.net.PlainSocketImpl.accept(PlainSocketImpl.java:199)
at java.net.ServerSocket.implAccept(ServerSocket.java:545)
at java.net.ServerSocket.accept(ServerSocket.java:513)
at sun.rmi.transport.tcp.TCPTransport$AcceptLoop.executeAcceptLoop(TCPTransport.java:405)
at sun.rmi.transport.tcp.TCPTransport$AcceptLoop.run(TCPTransport.java:377)
at java.lang.Thread.run(Thread.java:748)
# 查看指定线程id线程堆栈
[arthas@10580]$ thread 2
"Reference Handler" Id=2 WAITING on java.lang.ref.Reference$Lock@7e15a0e0
at java.lang.Object.wait(Native Method)
- waiting on java.lang.ref.Reference$Lock@7e15a0e0
at java.lang.Object.wait(Object.java:502)
at java.lang.ref.Reference.tryHandlePending(Reference.java:191)
at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:153)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62