Last active
November 3, 2016 20:10
-
-
Save ubergeek42/d721b226c01594ce5a3a61cd065d9822 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 StackTest implements Runnable { | |
public static long level = 0; | |
public static long stacksize = 1<<28; | |
public static long num(int n) { | |
level++; | |
return n==0 ? 0 : 1+num(n-1); | |
} | |
public void run() { | |
level = 0; | |
try { | |
int depth = 1<<23; | |
System.out.println("Recursion depth set to: " + depth); | |
System.out.println(num(depth)); | |
} catch (StackOverflowError e) { | |
System.out.println(" Stack overflow occurred"); | |
System.out.println(" Stack Level: " + level); | |
System.out.println(" Estimated Stack Size: " + ((level*16)/(1024)) + "k"); | |
} | |
} | |
public static void main(String[] args) { | |
System.out.println("Testing with thread + stacksize=" + stacksize); | |
Thread t = new Thread(null, new StackTest(), "main", stacksize); | |
t.start(); | |
try { | |
t.join(); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
System.out.println("Testing without thread: "); | |
new StackTest().run(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment