Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: resolved issue concerncing int overflow check in last cs

...

Code Block
bgColor#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;
  }
}

Any operations within the synchronized methods are now atomic with respect to other synchronized methods that lock on that object's monitor (intrinsic lock). It is now possible, for example, to add overflow checking within the synchronized getSum() method without introducing the possibility of a data race.

Risk Assessment

If operations on shared variables are not atomic, unexpected results can be produced. For example, information can be disclosed inadvertently because one user can receive information about other users.

...