Case A: No
Case B: Yes
Your analysis is correct. The synchronized keyword in the instance method is functionally equivalent to this:
public void someMethod() { synchronized(this) {
Since this differs in two contexts, they are not mutually exclusive. Note that even the same method could be called simultaneously for two different instances.
Edit
For case 2, you are wrong on 2A; it doesn't even make sense. The static synchronized method does not "belong" to the class instance; if it were done, it would not be static! It does not synchronize with any instance of the class (it does not have a reference to the instance to synchronize to!), So instead it synchronizes an object of class A The static synchronized method in class A equivalent to this:
public static void methodB() { synchronized (A.class) {
Your instance method will synchronize in the instance as shown above, so two threads can execute in parallel.
In case B then, obviously, they can also work in parallel, but you still do not understand the fundamental concept that the static method is not associated with any instance.
source share