当前位置:网站首页>Arthas-thread命令定位线程死锁
Arthas-thread命令定位线程死锁
2022-06-23 06:24:00 【qq_37279783】
模拟死锁的场景
public class Deadlock {
private static Object obj1 = new Object();
private static Object obj2 = new Object();
public static void main(String[] args) {
new Thread(() -> {
System.out.println("线程1执行");
synchronized (obj1) {
try {
TimeUnit.SECONDS.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
synchronized (obj2) {
}
}
}, "t1").start();
new Thread(() -> {
System.out.println("线程2执行");
synchronized (obj2) {
synchronized (obj1) {
}
}
}, "t2").start();
System.out.println("执行完毕");
}
}
通过thread命令定位
1,直接使用”thread“命令,输出线程统计信息。其中:BLOCKED 表示目前阻塞的线程数。
[[email protected]]$ thread
Threads Total: 26, NEW: 0, RUNNABLE: 8, BLOCKED: 2, WAITING: 4, TIMED_WAITING: 2, TERMINATED: 0, Internal threads: 10
ID NAME GROUP PRIORITY STATE %CPU DELTA_TIM TIME INTERRUPT DAEMON
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.000 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
14 arthas-timer system 5 WAITING 0.0 0.000 0:0.015 false true
17 arthas-NettyHttpTelnetBootstr system 5 RUNNABLE 0.0 0.000 0:0.015 false true
18 arthas-NettyWebsocketTtyBoots system 5 RUNNABLE 0.0 0.000 0:0.015 false true
19 arthas-NettyWebsocketTtyBoots system 5 RUNNABLE 0.0 0.000 0:0.015 false true
20 arthas-shell-server system 5 TIMED_WA 0.0 0.000 0:0.000 false true
21 arthas-session-manager system 5 TIMED_WA 0.0 0.000 0:0.000 false true
22 arthas-UserStat system 5 WAITING 0.0 0.000 0:0.000 false true
24 arthas-NettyHttpTelnetBootstr system 5 RUNNABLE 0.0 0.000 0:0.109 false true
25 arthas-command-execute system 5 RUNNABLE 0.0 0.000 0:0.015 false true
10 t1 main 5 BLOCKED 0.0 0.000 0:0.000 false false
11 t2 main 5 BLOCKED 0.0 0.000 0:0.000 false false
12 DestroyJavaVM main 5 RUNNABLE 0.0 0.000 0:0.156 false false
2,执行“thread -b”命令,找出当前阻塞其他线程的线程,即造成死锁的罪魁祸首
[[email protected]]$ thread -b
"t1" Id=10 BLOCKED on [email protected] owned by "t2" Id=11
at test.Deadlock.lambda$main$0(Deadlock.java:24)
- blocked on [email protected]
- locked [email protected] <---- but blocks 1 other threads!
at test.Deadlock$$Lambda$1/250421012.run(Unknown Source)
at java.lang.Thread.run(Thread.java:748)
注:上面这个命令直接输出了 造成死锁的线程ID,和具体的代码位置,以及当前线程一共阻塞的线程数量:“<—- but blocks 1 other threads!“。
3,其他线程命令:
thread –all, 显示所有的线程;
thread id, 显示指定线程的运行堆栈;
thread –state:查看指定状态的线程,如:thread –state BLOCKED;
thread -n 3:展示当前最忙的前N个线程并打印堆栈;
边栏推荐
猜你喜欢

In depth learning series 46: face image super score gfp-gan

Traversal of binary tree and related knowledge

初始化层实现

都是硬盘分区 C盘和D盘到底有什么区别?

MySQL mvcc multi version concurrency control

406 double pointer (27. remove elements, 977. square of ordered array, 15. sum of three numbers, 18. sum of four numbers)

MySQL(八) — 执行计划(Explain)详解

SSTable详解

The illustration shows three handshakes and four waves. Xiaobai can understand them

junit单元测试报错org.junit.runners.model.InvalidTestClassError: Invalid test class ‘xxx‘ .No runnable meth
随机推荐
Vs2013 ffmpeg environment configuration and common error handling
312. poke the balloon
Lombok的使用
898. 子数组按位或操作
316. 去除重复字母
Configuration and compilation of mingw-w64, msys and ffmpeg
About Supervision
MySQL(四) — MySQL存储引擎
NPM download error NPM err code error
898. subarray bitwise OR operation
Run typescript code directly using TS node
Xshell7 Download
UNET code implementation
滚动播报效果的实现
[STL] unordered of associated container_ Map Usage Summary
Interpreting the spirit of unity and cooperation in maker Education
300. longest increasing subsequence
Deep learning series 47: Super sub model real esrgan
407-栈与队列(232.用栈实现队列、225. 用队列实现栈)
MySQL总结