Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This compliant solution synchronizes the setValues() and getSum() methods to ensure atomicity.

Code Block
bgColor#FFcccc#ccccff
final class Adder {
  private int a;
  private int b;

  public synchronized int getSum() {
    return a + b;
  }

  public synchronized void setValues(int a, int b) {
    this.a = a;
    this.b = b;
  }
}

...