In this code two objects of DeadLock d1 and d2 is created then separate copy of all resources i.e., r1,r2,r3 will be created for d1 and d2 even then threads d1 and d2 enter deadlock while accessing the resources what is the reason can anyone please explain it correctly
import java.util.*;
class DeadLock extends Thread{
String r1="Oracle";
String r2="Sybase";
String r3="DB2";
DeadLock(String name){
super(name);
}
public void run(){
if(Thread.currentThread().getName().equals("Rama")){
acquireRamaResources();
}
else{
acquireSitaResources();
}
}
void acquireRamaResources(){
synchronized(r1){
System.out.println("Rama acquired Oracle");
synchronized (r2){
System.out.println("Rama acquired Sybase");
synchronized(r3){
System.out.println("Rama acquired DB2");
}
}
}
}
void acquireSitaResources(){
synchronized(r3){
System.out.println("Sita acquired DB2");
synchronized (r2){
System.out.println("Sita acquired Sybase");
synchronized(r1){
System.out.println("Sita acquired Oracle");
}
}
}
}
}
class Demo{
public static void main(String[]args){
DeadLock d1=new DeadLock("Rama");
DeadLock d2=new DeadLock("Sita");
d1.start();
d2.start();
}
}