-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathT.java
More file actions
41 lines (36 loc) · 889 Bytes
/
T.java
File metadata and controls
41 lines (36 loc) · 889 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package DeadLock;
import java.util.concurrent.TimeUnit;
/**
* @ClassName T
* @Description DeadLock演示
* @Author Chris Chen
* @Date 2019-07-24 15:21
* @Version 1.0
**/
public class T {
synchronized void m1() {
System.out.println("m1 start");
try {
TimeUnit.SECONDS.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
m2();
System.out.println("m1 end");
}
synchronized void m2() {
System.out.println("m2 start");
try {
TimeUnit.SECONDS.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
m1();
System.out.println("m2 end");
}
public static void main(String[] args) {
T t = new T();
new Thread(() -> t.m1()).start();
new Thread(() -> t.m2()).start();
}
}