Skip to content

Commit 198d157

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 7e0c5b8 + 482a963 commit 198d157

File tree

2 files changed

+15
-20
lines changed

2 files changed

+15
-20
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@
128128
- 讲讲java同步机制的wait和notify。
129129
- CAS机制是什么,如何解决ABA问题。
130130
- 多线程如果线程挂住了怎么办。
131+
- [深入分析AQS实现原理](https://mp.weixin.qq.com/s/2v0T3Nu7m2ka9D8PLl2XxQ)
131132
- countdowlatch和cyclicbarrier的内部原理和用法,以及相互之间的差别(比如
132133
- countdownlatch的await方法和是怎么实现的)。
133134
- 对AbstractQueuedSynchronizer了解多少,讲讲加锁和解锁的流程,独占锁和公平所加锁有什么不同。

src/main/java/com/algorithm/study/demo/thread/DeadlockTest.java

+14-20
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ public class DeadlockTest {
1010
private static Object o1=new Object();
1111
private static Object o2=new Object();
1212
public static void main(String[] args) {
13-
new Thread(){
14-
@Override
15-
public void run() {
13+
new Thread(()->{
1614
synchronized (o1){
1715
System.out.println("Thread1 get lock o1");
1816
try {
@@ -25,25 +23,21 @@ public void run() {
2523
}
2624
System.out.println("Thread1 end");
2725
}
28-
}
29-
}.start();
26+
}).start();
3027

31-
new Thread(){
32-
@Override
33-
public void run() {
34-
synchronized (o2){
35-
System.out.println("Thread2 get lock o1");
36-
try {
37-
TimeUnit.SECONDS.sleep(1);
38-
} catch (InterruptedException e) {
39-
e.printStackTrace();
40-
}
41-
synchronized (o1){
42-
System.out.println("Thread2 get lock o2");
43-
}
44-
System.out.println("Thread2 end");
28+
new Thread(() -> {
29+
synchronized (o2){
30+
System.out.println("Thread2 get lock o1");
31+
try {
32+
TimeUnit.SECONDS.sleep(1);
33+
} catch (InterruptedException e) {
34+
e.printStackTrace();
4535
}
36+
synchronized (o1){
37+
System.out.println("Thread2 get lock o2");
38+
}
39+
System.out.println("Thread2 end");
4640
}
47-
}.start();
41+
}).start();
4842
}
4943
}

0 commit comments

Comments
 (0)