Modify JVM args from inside the JVM

2020-02-14 05:57发布

Is there a way to modify the jvm args from inside of the jvm? Specifically, I want to be able to change the maximum heap size of the jvm from inside of it. Is this possible?

Edit: I guess I should add the reason I wanted to do this. I have a few Java programs that are run on different machines/platforms. These programs have configurations that are sourced at runtime and are different depending on the machine/environment the program's running one. Some of these configurations can be changed at runtime and the various programs automatically update themselves as the configurations change.

I wanted heap size to be one of these configuration parameters that is sourced at runtime like the rest of the configuration. If so, then the program could startup (with some default jvm args) then adjust itself based on the retrieved config.

标签: java jvm vmargs
7条回答
够拽才男人
2楼-- · 2020-02-14 06:56

Dynamically setting -Xmx for instance would be very helpful for controlling projected system resources (primarily footprint) for long running runtimes. One of many ramifications of course is bigger/longer GC overhead.

I know several large server machines running dozens and dozens of 1G+ heap JVMs. If these runtimes could have their high water mark scaled back during low-use times then you could hard manage your system resources much better.

查看更多
登录 后发表回答