aspose file tools*
The moose likes Threads and Synchronization and the fly likes Any Solution ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply locked New topic
Author

Any Solution ?

Abdul Mohsin
Ranch Hand

Joined: Apr 26, 2007
Posts: 111

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
Please do not double post in multiple forums. Thanks.
[ April 30, 2007: Message edited by: Barry Gaunt ]

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Please post replies in this thread because it is linked to from the SCJP forum.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Any Solution ?
 
Similar Threads
synchronized threads
two simultaneous run commands on same class.
Explain output of this program
locking??
Any Solution of Deadlock?