Synchoronizing a static method
public class A
{
public static synchronized void m1()
{
System.out.println("method1");
//some code here
}
public synchronized void m2()
{
System.out.println("method2");
//some code here
}
public static void main(
String[] args)
{
A a = new A();
a.m2();
a.m1();
A b = new B();
b.m2();
b.m1();
}
}
??In the above code the static method m1 and non-static method m2 are synchronized.
I just need to know how a lock will be gained by a
Thread calling method m1 since it is static and common to all instances.
Thanks in advance.