揭秘黑社会贩毒细节

 1 package 死锁;
 2 
 3 public class Lishihui {
 4     public static void main(String[] args) throws InterruptedException {
 5         new Thread(new A(true)).start();
 6         new Thread(new B(false)).start();
 7         Thread.currentThread().join(1000);
 8         System.out.println("大哥!...警察来了!........!");
 9     }
10 }
11 
12 class A implements Runnable{
13     boolean flag;
14     
15     public A (boolean flag) {this.flag = flag;}
16 
17     public void run() {
18         synchronized (Lock01.钱) {
19             System.out.println("先验货再给钱...");
20             synchronized (Lock01.货) {
21                 System.out.println("钱...");
22             }
23         }
24     }
25 }
26 
27 class B implements Runnable{
28     boolean flag;
29     
30     public B (boolean flag) {this.flag = flag;}
31 
32     public void run() {
33         synchronized (Lock01.货) {
34             System.out.println("先交钱再验货..");
35             synchronized (Lock01.钱) {
36                 System.out.println("货...");
37             }
38         }
39     }
40 }
41 
42 class Lock01{
43     static Object 货 = new Object();
44     static Object 钱 = new Object();
45 }

 

 

 

死锁最容易理解的死锁!点个赞呗!

posted @ 2018-05-24 09:37  马鞍山  阅读(186)  评论(0编辑  收藏  举报