Document thread safety
synchronized
keyword can appear in a method header,
it does not form a part of a method's API or contract. Synchronization
is part of the implementation, not part of the interface.
Note: some early Sun documentation (javadoc) included the synchronized
keyword in the description of methods. This error was corrected in Javadoc 1.2.
Example
Here, a concrete implementation of an interface uses synchronized
for some methods,
even though the interface methods themselves make no mention of it.
public interface ScientificTheory { void publish(); void predict(); boolean falsifyThroughMeasurement(); }
public final class LoopQuantumGravity implements ScientificTheory { @Override public synchronized void publish() { //..elided } @Override public synchronized void predict() { //..elided } @Override public boolean falsifyThroughMeasurement() { return true; //stub } }