如何在 per-thread 的基础上限制 Java 的筹码量?

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

标题问了一切,真的。如果无法直接在 JVM 中设置单个线程的堆栈大小,是否有其他选择?

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.

正如 Jacob G. 所指出的那样,它在同一文档中说(带有原始重点):

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