Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: removed volatile from CS(addition)...it uses synchronization

...

Code Block
bgColor#ccccff
private volatile int a;
private volatile int b;

public synchronized int getSum() throws ArithmeticException {
  // Check for integer overflow
  if( b > 0 ? a > Integer.MAX_VALUE - b : a < Integer.MIN_VALUE - b ) { 
    throw new ArithmeticException("Not in range");
  }

  return a + b;
}

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

...