Created
February 20, 2014 10:51
-
-
Save WarFox/9111092 to your computer and use it in GitHub Desktop.
static int is getting more count than AtomicInteger in single thread, why so?
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
import java.util.concurrent.atomic.AtomicInteger; | |
public class StackOverflow { | |
private static AtomicInteger atomicInteger = new AtomicInteger(0); | |
private static int staticInt = 0; | |
public static void main(String args[]) { | |
int atomicInt = atomicInteger.incrementAndGet(); | |
staticInt++; | |
try { | |
main(args); | |
} catch(StackOverflowError soe) { | |
System.out.println(atomicInt+":"+staticInt); | |
// staticInt gets more count, why so? | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Answer here
http://stackoverflow.com/questions/21905931/static-int-is-getting-more-count-than-atomicinteger-in-single-thread-why-so/21906149