标签:ble image width 总结 new t 释放 dump 命令 cep
public class DeadLockDemo { public static void main(String[] args) { final Object o1 = new Object(); final Object o2 = new Object(); Thread t1 = new Thread(new Runnable() { @Override public void run() { synchronized (o1){ //获取o1的锁 try{ Thread.sleep(1000); }catch (InterruptedException e){ e.printStackTrace(); } synchronized (o2){ //尝试获取02的锁 } } } }); Thread t2 = new Thread(new Runnable() { @Override public void run() { synchronized (o2){ //获取o2的锁 try{ Thread.sleep(1000); }catch (InterruptedException e){ e.printStackTrace(); } synchronized (o1){ //尝试获取01的锁 } } } }); //启动两个线程 t1.start(); t2.start(); } }
4、死锁分析:
Linux用jps命令找出运行的进程pid:(例子运行的程序名称为DeadLockDemo,即pid 为9345)
然后采用jstack (jstack pid)命令显示当前jvm的dump信息:
信息最后我们可以清晰看到(发生了死锁,和对象地址):
Found one Java-level deadlock: ============================= "Thread-1": waiting to lock monitor 0x00007f6f50004e28 (object 0x000000058015fa18, a java.lang.Object), which is held by "Thread-0" "Thread-0": waiting to lock monitor 0x00007f6f500062c8 (object 0x000000058015fa28, a java.lang.Object), which is held by "Thread-1" Java stack information for the threads listed above: =================================================== "Thread-1": at DeadLockDemo$2.run(DeadLockDemo.java:35) - waiting to lock <0x000000058015fa18> (a java.lang.Object) - locked <0x000000058015fa28> (a java.lang.Object) at java.lang.Thread.run(Thread.java:745) "Thread-0": at DeadLockDemo$1.run(DeadLockDemo.java:18) - waiting to lock <0x000000058015fa28> (a java.lang.Object) - locked <0x000000058015fa18> (a java.lang.Object) at java.lang.Thread.run(Thread.java:745) Found 1 deadlock.
标签:ble image width 总结 new t 释放 dump 命令 cep
原文地址:https://www.cnblogs.com/lihao7/p/10268070.html