public final class Counter {
private long value = 0;
public synchronized long getValue() {
return value;
}
public synchronized long increment() {
if(value == Long.MAX_SIZE) {
throw new IllegalStateException("counter overflow")
}
return ++counter;
}
}
When you subscribe to the blog, we will send you an e-mail when there are new updates on the site so you wouldn't miss them.
評論