public class IncrementException extends Exception {} |
public class BalkingBoundedCounter { |
protected long count_ = BoundedCounter.MIN; |
public synchronized void inc() throws IncrementException { |
if (count_ >= BoundedCounter.MAX) |
throw new IncrementException(); |
else |
++ count_; |
} |
} |