码迷,mamicode.com
首页 > 编程语言 > 详细

JVM调优之jstack找出发生死锁的线程

时间:2016-08-30 17:32:29      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:

1、执行死锁程序

2、执行 jstack -l 21733 | more

结果如下:

技术分享

死锁程序:

public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("start the example------");
final Object obj_1 = new Object();
final Object obj_2 = new Object();

Thread t1 = new Thread("t1") {
@Override
public void run() {
synchronized (obj_1) {
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
synchronized (this) {
}
synchronized (obj_2) {
System.out.println("thread t1 done");
}
}
}
};
Thread t2 = new Thread("t2") {
public void run() {
synchronized (obj_2) {
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

synchronized (obj_1) {
System.out.println("thread t2 done.");
}

}
}
};

t1.start();
t2.start();
}

JVM调优之jstack找出发生死锁的线程

标签:

原文地址:http://www.cnblogs.com/chengJAVA/p/5822402.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!