This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
What's the best way to detect deadlock and remove deadlock?
Example:
public class RunDeadLock { public static void main(String[] args) { Thread1 t1= new Thread1(); Thread2 t2= new Thread2();
t1.start(); t2.start();
} }
public class Thread1 extends Thread { public void run(){ ThreadResource1.go1(); } }
public class Thread2 extends Thread { public void run(){ ThreadResource2.go2(); } }
public class ThreadResource2 { public static synchronized void go2(){ System.out.println("Entered in resource 2"); System.out.println(Thread.currentThread().getName()); try{ Thread.sleep(5000); }catch(Exception e){}
ThreadResource1.go1(); System.out.println("Exiting from resource");
} }
public class ThreadResource1 { public static synchronized void go1(){ System.out.println("Entered in resource1"); System.out.println(Thread.currentThread().getName()); try{ Thread.sleep(5000); }catch(Exception e){} ThreadResource2.go2(); System.out.println("Exiting from resource");
} }
How to remove deadlock?
Regards,
Abdul Mohsin
Regards, Abdul Mohsin
Barry Gaunt
Ranch Hand
Joined: Aug 03, 2002
Posts: 7729
posted
0
Please do not double post in multiple forums. Thanks. [ April 30, 2007: Message edited by: Barry Gaunt ]