Skip to content

Instantly share code, notes, and snippets.

@WarFox
Created February 20, 2014 10:51
Show Gist options
  • Save WarFox/9111092 to your computer and use it in GitHub Desktop.
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?
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