OnJava8-Examples/lowlevel/EvenProducer.java
2017-01-12 16:49:36 -08:00

27 lines
619 B
Java

// lowlevel/EvenProducer.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.
// When threads collide
public class EvenProducer extends IntGenerator {
private int currentEvenValue = 0;
@Override
public int next() {
++currentEvenValue; // [1]
++currentEvenValue;
return currentEvenValue;
}
public static void main(String[] args) {
EvenChecker.test(new EvenProducer());
}
}
/* Output:
1563 not even!
1573 not even!
1571 not even!
1569 not even!
1567 not even!
1565 not even!
*/