#概念: 一组相互竞争资源的线程因为互相等待,导致“永久”阻塞的现象
设计一个死锁代码
/**
* @创建者: hanyi
* @创建时间: 2022/1/14 17:44
* @描述: 死锁测试
*/
public class DeadLock {
public static void main(String[] args) {
Object o = new Object();
Object o1 = new Object();
new Thread(()->{
synchronized (o){
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
synchronized (o1){
System.out.println("i get o2");
}
}
}).start();
new Thread(()->{
synchronized (o1){
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
synchronized (o){
System.out.println("i get o");
}
}
}).start();
}
}