00001 public class Deadlock { 00002 static Lock lock1; 00003 static Lock lock2; 00004 static int state; 00005 00006 public static void main(String[] args) { 00007 lock1 = new Lock(); 00008 lock2 = new Lock(); 00009 Process1 p1 = new Process1(); 00010 Process2 p2 = new Process2(); 00011 p1.start(); 00012 p2.start(); 00013 } 00014 } 00015 00016 class Process1 extends Thread { 00017 public void run() { 00018 Deadlock.state++; 00019 synchronized (Deadlock.lock1) { 00020 synchronized (Deadlock.lock2) { 00021 Deadlock.state++; 00022 } 00023 } 00024 } 00025 } 00026 00027 class Process2 extends Thread { 00028 public void run() { 00029 Deadlock.state++; 00030 synchronized (Deadlock.lock2) { 00031 synchronized (Deadlock.lock1) { 00032 Deadlock.state++; 00033 } 00034 } 00035 } 00036 } 00037 00038 class Lock { 00039 } 00040 00041