Advertisement
Advertisement
class A
{
synchronized public void m(A a,B b)
{
System.out.print(Thread.currentThread().getName());
System.out.println(" thread is in A'a m() method, trying to call B's m() method");
b.m(a,b); //Line1
}
}
class B
{
synchronized public void m( A a,B b)
{
System.out.print(Thread.currentThread().getName());
System.out.println(" is in B's m() method, trying to call A's m() method");
a.m(a,b); //Line2
}
}
class C implements Runnable
{
A a= new A(); //Line3
B b= new B(); //Line4
Thread t;
C()
{
t= new Thread(this, "Thread2"); //Line5
t.start(); //Line6
a.m(a,b); //Line7
}
public void run()
{
b.m(a,b); //Line8
}
public static void main(String []ar)
{
new C(); //Line9
}
}
main thread is in A'a m() method, trying to call B's m() method
newThread is in B's m() method, trying to call A's m() method
Advertisement
Advertisement
Please check our latest addition
C#, PYTHON and DJANGO
Advertisement