Thanks Ernest Friedman-Hill & Azriel Abramovich for replying my query. Is there any way i can
test this.
I tried this by running two seperate threads for printing 10000 numbers, but i am not able to differentiate it. Please help me to sort out this issue.
public class Zevel
{
Object lock1 = new Object();
Object lock2 = new Object();
int i;
public void a()
{ synchronized(lock1)
{
i++;
System.out.println("Inside a");
System.out.println(i);
}
}
public void b()
{ synchronized(lock2)
{
System.out.println("Inside b");
}
}
public static void main(
String args[])
{
Zevel z= new Zevel();
for (int i= 0;i<10000;i++)
z.a();
z.b();
}
}
Regards,
M.S.Raman
Originally posted by Azriel Abramovich:
sorry, hit the TAB key and then pressed space.... this is to continue:
consider the following example:
Even in this case, propagation of calls from a() to b() will be possible (within the synced blox) because they have the same monitor owner.
In your example and in mine if two different monitor owners (threads) would try to 'use' the same synched area of code the synch mechanism would get to work and block one thread until the other is done.
Hope this helped.
This was made this way to avoid dead-locks.