OnJava8-Examples/lowlevel/AtomicEvenSupplier.java
2016-12-30 17:23:13 -08:00

22 lines
686 B
Java

// lowlevel/AtomicEvenSupplier.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
// {IgnoreOutput} // No output validation
import java.util.concurrent.atomic.*;
import onjava.TimedAbort;
public class AtomicEvenSupplier extends IntSupplier {
private AtomicInteger currentEvenValue =
new AtomicInteger(0);
@Override
public int next() {
return currentEvenValue.addAndGet(2);
}
public static void main(String[] args) {
new TimedAbort(4);
EvenChecker.test(new AtomicEvenSupplier());
}
}