1 | public class IncrementException extends Exception {} |
2 | |
3 | public class BalkingBoundedCounter { |
4 | protected long count_ = BoundedCounter.MIN; |
5 | |
6 | public synchronized void inc() throws IncrementException { |
7 | if (count_ >= BoundedCounter.MAX) |
8 | throw new IncrementException(); |
9 | else |
10 | ++ count_; |
11 | } |
12 | } |
13 |