16 lines
451 B
Java
16 lines
451 B
Java
|
//: concurrency/AtomicEvenGenerator.java
|
||
|
// Atomic classes are occasionally useful in regular code.
|
||
|
// {RunByHand}
|
||
|
import java.util.concurrent.atomic.*;
|
||
|
|
||
|
public class AtomicEvenGenerator extends IntGenerator {
|
||
|
private AtomicInteger currentEvenValue =
|
||
|
new AtomicInteger(0);
|
||
|
public int next() {
|
||
|
return currentEvenValue.addAndGet(2);
|
||
|
}
|
||
|
public static void main(String[] args) {
|
||
|
EvenChecker.test(new AtomicEvenGenerator());
|
||
|
}
|
||
|
} ///:~
|