...
This compliant solution synchronizes the setValues() and getSum() methods to ensure atomicity.
| Code Block | ||
|---|---|---|
| ||
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;
}
}
|
...