...
Code Block | ||
---|---|---|
| ||
private volatile int a; private volatile int b; public 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 intvoid setValues(int a, int b) { this.a = a; this.b = b; } |
...
Code Block | ||
---|---|---|
| ||
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 intvoid setValues(int a, int b) { this.a = a; this.b = b; } |
...