Skip to content

Instantly share code, notes, and snippets.

@coderplay
Created May 16, 2012 06:02
Show Gist options
  • Save coderplay/2707915 to your computer and use it in GitHub Desktop.
Save coderplay/2707915 to your computer and use it in GitHub Desktop.
what every java programmer should know about cpu
public class IncrementVolatileLong {
private static volatile long value;
public static void increment() {
while (value < 500000000L) {
value++;
}
}
public static void main(String[] args) throws Exception {
Thread.sleep(5000);
value = 0;
increment();
value = 0;
long start = System.nanoTime();
increment();
System.out.println("Cost time: " + (System.nanoTime() - start));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment