javastackjava-threadsstack-size

How to limit Java's stack size on a per-thread basis?


The title asks it all, really. If setting the stack size of an individual thread directly in the JVM isn't possible, are there any alternatives?


Solution

  • Use the docs:

    public Thread(ThreadGroup group,
                  Runnable target,
                  String name,
                  long stackSize)
    

    ...

    stackSize - the desired stack size for the new thread, or zero to indicate that this parameter is to be ignored.

    As pointed out by Jacob G., it says in the same documentation (with original emphasis):

    On some platforms, the value of the stackSize parameter may have no effect whatsoever.