class Counter {
private long count;
synchronized void increment(long amount) {
if (amount < 1) {
throw new IllegalArgumentException("Only increments!");
}
this.count += amount;
}
}
/** thread safe */
class Counter {
/** guarded by 'this' */
private long count;
synchronized void increment(long amount) {
if (amount < 1) {
throw new IllegalArgumentException("Only increments!");
}
this.count += amount;
}
}