File tree Expand file tree Collapse file tree 2 files changed +15
-20
lines changed
src/main/java/com/algorithm/study/demo/thread Expand file tree Collapse file tree 2 files changed +15
-20
lines changed Original file line number Diff line number Diff line change 129129 - 讲讲java同步机制的wait和notify。
130130 - CAS机制是什么,如何解决ABA问题。
131131 - 多线程如果线程挂住了怎么办。
132+ - [ 深入分析AQS实现原理] ( https://mp.weixin.qq.com/s/2v0T3Nu7m2ka9D8PLl2XxQ )
132133 - countdowlatch和cyclicbarrier的内部原理和用法,以及相互之间的差别(比如
133134 - countdownlatch的await方法和是怎么实现的)。
134135 - 对AbstractQueuedSynchronizer了解多少,讲讲加锁和解锁的流程,独占锁和公平所加锁有什么不同。
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments