File tree Expand file tree Collapse file tree
src/main/java/com/concurrent/newstart Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package com .concurrent .newstart ;
2+
3+ /**
4+ * @author by chenzhuo
5+ * @Description 死锁
6+ * @Date 2019/7/10 16:02
7+ **/
8+ public class DeadLockDemon {
9+ private static String A = "A" ;
10+ private static String B = "B" ;
11+
12+ public static void main (String [] args ) {
13+ new DeadLockDemon ().deadLock ();
14+ }
15+
16+ private void deadLock () {
17+ Thread thread = new Thread (() -> {
18+ synchronized (A ) {
19+ try {
20+ Thread .sleep (2000 );
21+ } catch (InterruptedException e ) {
22+ e .printStackTrace ();
23+ }
24+ synchronized (B ) {
25+ System .err .println ("B" );
26+ }
27+ }
28+
29+ });
30+ Thread thread1 = new Thread (() -> {
31+ synchronized (B ) {
32+ synchronized (A ) {
33+ System .err .println ("A" );
34+ }
35+ }
36+ });
37+ thread .start ();
38+ thread1 .start ();
39+ }
40+ }
Original file line number Diff line number Diff line change 1+ /**
2+ * @Description 7.10~7.24 Java并发编程 整理输出
3+ * @Date 2019/7/10 16:01
4+ * @author by chenzhuo
5+ **/
6+ package com .concurrent .newstart ;
You can’t perform that action at this time.
0 commit comments