OnJava8-Examples/lowlevel/AtomicEvenProducer.java
2017-05-03 16:02:28 -06:00

23 lines
680 B
Java

// lowlevel/AtomicEvenProducer.java
// (c)2017 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// Atomic classes are occasionally useful in regular code
// {ValidateByHand} AppVeyor CI has trouble
import java.util.concurrent.atomic.*;
public class AtomicEvenProducer extends IntGenerator {
private AtomicInteger currentEvenValue =
new AtomicInteger(0);
@Override
public int next() {
return currentEvenValue.addAndGet(2);
}
public static void main(String[] args) {
EvenChecker.test(new AtomicEvenProducer());
}
}
/* Output:
No odd numbers discovered
*/