Note that there are some explanatory texts on larger screens.

plurals
  1. POVariable depth recursion in Java
    primarykey
    data
    text
    <p>So I'm doing a little experiment on exactly how far recursion can go in the Java language since I'm taking a class on concurrency and learning about Java's threading mechanisms. Right now I'm running a Intel i5 Quad-core with 2.8 GHz and 4GB of RAM. I'm running on Windows 7 with x64 and in Eclipse with the standard JRE? Not sure about that last part I just downloaded something from Sun's website.</p> <p>Anyway,</p> <pre><code>public class StacksizeTest implements Runnable { int depth = 0; public void run() { try { doOverflow(); } catch (StackOverflowError e) { System.out.print("Overflow ocurred at depth " + depth + ".\n"); } } void doOverflow() { depth += 1; doOverflow(); } public static void main(String argv[]) { Thread mt = new Thread(new StacksizeTest()); mt.start(); mt.run(); } } </code></pre> <p>I'm also running with the default call stack size, which im pretty sure is 512Mb according to the settings file.</p> <p>So when I run the program and start a new thread I keep getting variable depths, as well as the print statement printing twice. The print statement makes sense I think because it should be running mt on a new thread. What I'm confused about is if I exclude .start() and just call .run() the "depth" is always the same (about 11,500 or so), but when I use .start() I'm getting variable depths. a couple have been 22789, 22330, and 22381. I'm having difficulty understanding why this is. Could someone possibly shed some light on this issue?</p> <p>Thanks,</p> <p>Matt</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload