Skip to content

Commit 807f12a

Browse files
author
jossc
committed
Merge remote-tracking branch 'origin/master'
2 parents 10e9f0b + 746ce25 commit 807f12a

2 files changed

Lines changed: 46 additions & 0 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.concurrent.newstart;
2+
3+
/**
4+
* @author by chenzhuo
5+
* @Description 死锁
6+
* @Date 2019/7/10 16:02
7+
**/
8+
public class DeadLockDemon {
9+
private static String A = "A";
10+
private static String B = "B";
11+
12+
public static void main(String[] args) {
13+
new DeadLockDemon().deadLock();
14+
}
15+
16+
private void deadLock() {
17+
Thread thread = new Thread(() -> {
18+
synchronized (A) {
19+
try {
20+
Thread.sleep(2000);
21+
} catch (InterruptedException e) {
22+
e.printStackTrace();
23+
}
24+
synchronized (B) {
25+
System.err.println("B");
26+
}
27+
}
28+
29+
});
30+
Thread thread1 = new Thread(() -> {
31+
synchronized (B) {
32+
synchronized (A) {
33+
System.err.println("A");
34+
}
35+
}
36+
});
37+
thread.start();
38+
thread1.start();
39+
}
40+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
* @Description 7.10~7.24 Java并发编程 整理输出
3+
* @Date 2019/7/10 16:01
4+
* @author by chenzhuo
5+
**/
6+
package com.concurrent.newstart;

0 commit comments

Comments
 (0)