2017-01-15 16:00:44 -08:00
|
|
|
// lowlevel/SafeReturn.java
|
2020-10-07 13:35:40 -06:00
|
|
|
// (c)2020 MindView LLC: see Copyright.txt
|
2017-01-15 16:00:44 -08:00
|
|
|
// We make no guarantees that this code is fit for any purpose.
|
|
|
|
// Visit http://OnJava8.com for more book information.
|
|
|
|
import java.util.function.*;
|
|
|
|
import java.util.concurrent.*;
|
|
|
|
|
|
|
|
public class SafeReturn extends IntTestable {
|
|
|
|
private int i = 0;
|
|
|
|
public synchronized int getAsInt() { return i; }
|
|
|
|
public synchronized void evenIncrement() {
|
|
|
|
i++; i++;
|
|
|
|
}
|
|
|
|
public static void main(String[] args) {
|
|
|
|
Atomicity.test(new SafeReturn());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Output:
|
|
|
|
No failures found
|
|
|
|
*/
|