...
Code Block | ||
---|---|---|
| ||
final class Adder {
private final AtomicInteger a = new AtomicInteger();
private final AtomicInteger b = new AtomicInteger();
public int getSum() throws ArithmeticException {
return a.get() + b.get(); // or, return a.getAndAdd(b.get());
}
public void setValues(int a, int b) {
this.a.set(a);
this.b.set(b);
}
}
|
...
Code Block | ||
---|---|---|
| ||
final class Adder {
private final AtomicInteger a = new AtomicInteger();
private final AtomicInteger b = new AtomicInteger();
public synchronized int getSum() throws ArithmeticException {
return a.get() + b.get(); // or, return a.getAndAdd(b.get());
}
public synchronized void setValues(int a, int b) {
this.a.set(a);
this.b.set(b);
}
}
|
...