-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeadLockTest.java
More file actions
37 lines (34 loc) · 907 Bytes
/
DeadLockTest.java
File metadata and controls
37 lines (34 loc) · 907 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
/**
* @author hyperglory
* @date 2017/3/3 16:45
*/
public class DeadLockTest {
private static String A = "A";
private static String B = "B";
public static void main(String[] args) {
deadLock();
}
private static void deadLock() {
Thread thread1 = new Thread(() -> {
synchronized (A) {
try {
Thread.currentThread().sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
synchronized (B) {
System.out.println("1");
}
}
});
Thread thread2 = new Thread(() -> {
synchronized (B) {
synchronized (A) {
System.out.println("2");
}
}
});
thread1.start();
thread2.start();
}
}