File tree 2 files changed +15
-20
lines changed
src/main/java/com/algorithm/study/demo/thread
2 files changed +15
-20
lines changed Original file line number Diff line number Diff line change 128
128
- 讲讲java同步机制的wait和notify。
129
129
- CAS机制是什么,如何解决ABA问题。
130
130
- 多线程如果线程挂住了怎么办。
131
+ - [ 深入分析AQS实现原理] ( https://mp.weixin.qq.com/s/2v0T3Nu7m2ka9D8PLl2XxQ )
131
132
- countdowlatch和cyclicbarrier的内部原理和用法,以及相互之间的差别(比如
132
133
- countdownlatch的await方法和是怎么实现的)。
133
134
- 对AbstractQueuedSynchronizer了解多少,讲讲加锁和解锁的流程,独占锁和公平所加锁有什么不同。
Original file line number Diff line number Diff line change @@ -10,9 +10,7 @@ public class DeadlockTest {
10
10
private static Object o1 =new Object ();
11
11
private static Object o2 =new Object ();
12
12
public static void main (String [] args ) {
13
- new Thread (){
14
- @ Override
15
- public void run () {
13
+ new Thread (()->{
16
14
synchronized (o1 ){
17
15
System .out .println ("Thread1 get lock o1" );
18
16
try {
@@ -25,25 +23,21 @@ public void run() {
25
23
}
26
24
System .out .println ("Thread1 end" );
27
25
}
28
- }
29
- }.start ();
26
+ }).start ();
30
27
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 ();
45
35
}
36
+ synchronized (o1 ){
37
+ System .out .println ("Thread2 get lock o2" );
38
+ }
39
+ System .out .println ("Thread2 end" );
46
40
}
47
- }.start ();
41
+ }) .start ();
48
42
}
49
43
}
You can’t perform that action at this time.
0 commit comments