when I have a method like
public void unsynchronizedMethod(){
callSynchronizedMethod();
//dosomestuff after this line
}
does it mean that all content, after calling callSynchronizedMethod() in the unsynchronizedMethod()-Method, is implicitly synchronized?
Synchronization is defined in a straightforward manner:
synchronizedmethod: within the execution of that methodsynchronizedblock: within the execution of that blockHere are the relevant excerpts from Java Language Specification 3rd Edition:
JLS 14.19 The
synchronizedStatementsynchronizedmethods is semantically identical to asynchronizedstatement applied to the whole method (§JLS 8.4.3.6. The lock is obtained from eitherthis(if it’s an instance method) or theClassobject associated with the method’s class (if it’s astaticmethod; you can’t refer tothisin astaticcontext).So to answer the original question, given this snippet:
Note that this is by design: you should always strive to minimize synchronization to only critical sections. Outside of those critical sections, there is no lingering effect from earlier synchronization.
See also
Related questions