class A {
public synchronized void myOneMethod() {
// ...
}
}
class B extends A {
public synchronized void myOtherMethod() {
// ...
}
}
From the conceptual viewpoint, the mutex integrity of some inheritance scenarios would be broken if synchonized
methods of class A
would only protect A
's data in the context of subclass B
. After all, not all of A
's data is required to be private
.
Imagine that you want to slightly extend the functionality of one method of A
while keeping the rest of A
's functionality including mutex protection. If A
were only protecting itself, you would end up having to override all of A
's synchronized
methods to lift the original synchronization mechanism to the new subclass. Not very attractive and also not very efficient.