eliminated volatile

This commit is contained in:
Bruce Eckel 2017-01-02 14:20:31 -08:00
parent 8c4b4e7896
commit 620703ef6f

View File

@ -7,13 +7,11 @@ import java.util.function.*;
import onjava.Timer; import onjava.Timer;
public class Summing { public class Summing {
static volatile long result;
static void timeTest(String id, long checkValue, static void timeTest(String id, long checkValue,
LongSupplier operation) { LongSupplier operation) {
System.out.print(id + ": "); System.out.print(id + ": ");
Timer timer = new Timer(); Timer timer = new Timer();
// Prevent optimization: long result = operation.getAsLong();
result = operation.getAsLong();
if(result == checkValue) if(result == checkValue)
System.out.println(timer.duration() + "ms"); System.out.println(timer.duration() + "ms");
else else