For the following code:
method() {
object.externalMethod();
}
If externalMethod() is not thread safe. Say, it starts multiple threads, which do some unsafe stuffs. Can we still make sure method() is thread safe, with no knowledge of externalMethod's implementation? I believe adding "synchronized" is not enough here.
Adding synchronized is enough - so long as you synchronize onto all access to the object, not just onto all access to externalMethod.
Unless of course the internals of the object are failing to synchronize properly, in which case you are indeed unable to do anything. The object should document the correct way to interact with it though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With