You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 「一入 Java 深似海 」/代码/segmentfault/deep-in-java/stage-3/stage-3-lesson-2/src/main/java/com/segmentfault/deep/in/java/concurrency/DeadLockDemo.java
+10Lines changed: 10 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -11,6 +11,11 @@ public static void main(String[] args) {
11
11
synchronized (m1) {
12
12
System.out.printf("Thread[ ID : %d] holds m1\n", Thread.currentThread().getId());
13
13
14
+
try {
15
+
Thread.sleep(1000);
16
+
} catch (InterruptedExceptione) {
17
+
e.printStackTrace();
18
+
}
14
19
synchronized (m2) {
15
20
System.out.printf("Thread[ ID : %d] holds m2\n", Thread.currentThread().getId());
16
21
}
@@ -21,6 +26,11 @@ public static void main(String[] args) {
21
26
synchronized (m2) {
22
27
System.out.printf("Thread[ ID : %d] holds m2\n", Thread.currentThread().getId());
23
28
29
+
try {
30
+
Thread.sleep(1000);
31
+
} catch (InterruptedExceptione) {
32
+
e.printStackTrace();
33
+
}
24
34
synchronized (m1) {
25
35
System.out.printf("Thread[ ID : %d] holds m1\n", Thread.currentThread().getId());
0 commit comments