以编程方式设置最大 Java 堆大小

2022-01-16 00:00:00 jvm java heap-memory

有没有办法以编程方式设置最大 java 堆大小而不是作为 vm 参数?

Is there a way to set the max java heap size programmatically instead of as a vm argument?

类似:

System.getProperties().put("<heap variable>", "1000m");

推荐答案

不适用于任何 Hotspot JVM.JVM 堆参数只能在命令行中指定,然后在 JVM 的生命周期内固定.

Not with any Hotspot JVM. The JVM heap parameters can only be specified on the command line, and are then fixed for the lifetime of the JVM.

使用 Hotspot Java 实现,更改"应用程序的堆大小的唯一方法是在具有不同命令行参数的新 JVM 中重新启动它.

With Hotspot Java implementations, the only way to "change" the heap size of an application is to relaunch it in a new JVM with different command line parameters.

(我隐约记得其他一些供应商的 JVM确实允许在运行的 JVM 中更改一些堆参数.也许有人可以澄清一下.)

(I vaguely recall that JVMs from some other vendors do allow some heap parameters to be changed in a running JVM. Perhaps someone can clarify.)

相关文章