OnJava8-Examples/concurrency/AtomicEvenGenerator.java

17 lines
474 B
Java
Raw Normal View History

2015-04-20 15:36:01 -07:00
//: concurrency/AtomicEvenGenerator.java
// Atomic classes are occasionally useful in regular code.
2015-05-05 11:20:13 -07:00
// {TimeOutDuringTesting}
2015-04-20 15:36:01 -07:00
import java.util.concurrent.atomic.*;
public class AtomicEvenGenerator extends IntGenerator {
private AtomicInteger currentEvenValue =
new AtomicInteger(0);
2015-05-05 11:20:13 -07:00
@Override
2015-04-20 15:36:01 -07:00
public int next() {
return currentEvenValue.addAndGet(2);
}
public static void main(String[] args) {
EvenChecker.test(new AtomicEvenGenerator());
}
} ///:~