Bookmark Topic Watch Topic
  • New Topic

Any Solution ?

 
Abdul Mohsin
Ranch Hand
Posts: 111
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please do not double post in multiple forums. Thanks.
[ April 30, 2007: Message edited by: Barry Gaunt ]
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please post replies in this thread because it is linked to from the SCJP forum.
 
    Bookmark Topic Watch Topic
  • New Topic