I am learning Threads in Java and I am interested in how to control access synchronization between static and instance methods of a class, since the synchronization of static methods in a class is independent of the synchronization of instance methods on class objects.
At the moment I can not find any situation in real life, so I make an assumption:
Two classes A and B, class A have static methods with a formal parameter of class B, as well as instance methods. Then I create two threads to execute two methods of A.
How many ways to keep state below obj is always consistent?
class B { ... }
class A {
public synchronized void instanceMethod(B obj){ ... };
public static synchronized void staticMethod(B obj){ ... };
public static void main(String[] args){
B obj = new B();
}
}
Thanks for the advanced.