.实现简单的死锁案例
public class RunnableDemo implements Runnable {
private String lockA;
private String lockB;
public RunnableDemo(String lockA,String lockB){
this.lockA=lockA;
this.lockB=lockB;
}
@Override
public void run() {
synchronized (lockA){
System.out.println(Thread.currentThread().getName()+"lock one:"+lockA);
synchronized (lockB){
System.out.println(Thread.currentThread().getName()+"lock two"+lockB);
}
}
}
public static void main(String[] args) {
String lock1="LOCK1";
String lock2="LOCK2";
new Thread(new RunnableDemo(lock1,lock2),"AA").start();
new Thread(new RunnableDemo(lock2,lock1),"BB").start();
}
查看当前运行的线程
- 检测当前堆栈的使用情况的指令
分析造成死锁的线程