Created
May 16, 2012 06:02
-
-
Save coderplay/2707915 to your computer and use it in GitHub Desktop.
what every java programmer should know about cpu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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