About Question enthuware.ocpjp.v7.2.1482 :
Posted: Sun Oct 27, 2013 7:57 am
In such a case, If we first try to get a lock on obj1 in both m1() and m2() - why the deadlock cannot be avoided?
i tried the above code and it does results in a deadlock as well.
Code: Select all
public void m1()
{
synchronized(obj1)
{
System.out.print("1 ");
synchronized(obj2)
{
System.out.println("2");
}
}
}
public void m2()
{
synchronized(obj1)
{
System.out.print("2 ");
synchronized(obj2)
{
System.out.println("1");
}
}
}