Synchronized is implementation detail

Although the 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.


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() {
  @Override public synchronized void predict() {
  @Override public boolean falsifyThroughMeasurement() {
    return true; //stub 

See Also :
Document thread safety
Would you use this technique?
Yes   No   Undecided   
© 2018 Hirondelle Systems | Source Code | Contact | License | RSS
Individual code snippets can be used under this BSD license - Last updated on September 21, 2013.
Over 2,000,000 unique IPs last year - Built with WEB4J.
- In Memoriam : Bill Dirani -