Why does the count of calls of a recursive method causing a StackOverflowError vary between program runs? [duplicate]
问题 This question already has an answer here: Why is the max recursion depth I can reach non-deterministic? 4 answers A simple class for demonstration purposes: public class Main { private static int counter = 0; public static void main(String[] args) { try { f(); } catch (StackOverflowError e) { System.out.println(counter); } } private static void f() { counter++; f(); } } I executed the above program 5 times, the results are: 22025 22117 15234 21993 21430 Why are the results different each time