揭秘黑社会贩毒细节
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 }
死锁最容易理解的死锁!点个赞呗!
传播知识,分享快乐!
作者:IT_BULL
出处:http://www.cnblogs.com/itBulls/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
博客园-博客园。