deadLock
程序员文章站
2022-06-11 21:44:06
...
public class DeadLock {
private static Object o1 = new Object();
private static Object o2 = new Object();
public static void main(String[] args) {
new Thread(()->{
synchronized (o1) {
System.out.println("t1 ---Get o1");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
//需要资源o2 但是 t2 独占(未释放) -->互相竞争资源-->死锁
synchronized(o2){
System.out.println("t1 ---Get o2");
}
}
}).start();
new Thread(()->{
//抢占资源o2
synchronized (o2) {
System.out.println("t2 ---Get o2");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
//需要资源 o1,但是 t1 独占(未释放) -->互相竞争资源-->死锁
synchronized (o1) {
System.out.println("t2 ---Get o1");
}
}
}).start();
}
}
上一篇: Ubuntu 16.04配置ORB_SLAM过程及问题记录
下一篇: php.ini配置
推荐阅读
-
mysql报错:Deadlock found when trying to get lock; try restarting transaction的解决方法
-
数据库死锁的问题,Deadlock found when trying to get lock; try restarting transaction at Query.formatError
-
semaphore deadlock
-
关于MySQL死锁检测机制参数innodb_deadlock_detect设置的一点思考
-
MySQL DeadLock故障排查全过程记录
-
【C#】await & Result DeadLock
-
查询sql遇到deadlock问题的解决_MySQL
-
Global Enqueue Services Deadlock导致节点重启
-
sql server deadlock跟踪的四种方法
-
使用默认system_health分析死锁(Deadlock)