Change JVM arguments from inside JVM

Is there a way to change jvm args from inside jvm? In particular, I want to be able to change the maximum jvm heap size from the inside. Is it possible?

Change I think I should add the reason I wanted to do this. I have several Java programs that run on different computers / platforms. These programs have configurations that are received at runtime and vary depending on the machine / environment in which the program runs. Some of these configurations can be changed at run time, and various programs automatically update themselves as configurations change.

I wanted the heap size to be one of these configuration parameters that was obtained at runtime, like the rest of the configuration. If so, then the program can start (with some default arguments to jvm), and then configure itself based on the extracted config.

+3
source share
7 answers

This is a serious, completely slurred thought:

... what if you spawned a new java instance (with new settings) from the current jvm, then it killed the old process from the new? I have no idea if this will help (or even work) ...

+6
source

You cannot change these settings simply because it compromises the security of the system.

If the administrator wants to allow a certain program to have certain capabilities by installing a security manager, this would be a serious problem if you could disable it.

In any case, the program should not change things similar to the requirements for its memory at runtime - they should be known and configured by the administrator. There is no reason your program will need to do this at runtime. If this really needs to be changed, perhaps the reason for qustion is why isn't a dude like an administrator doing this?

+3
source

In particular, I want to be able to change the maximum jvm heap size from the inside. Is it possible?

No.

+2
source

With JRockit, you can at least specify the size of the heap.

JVMFactory.getJVM().getMemorySystem().suggestHeapSize(100*1000*1000); 

See JMAPI for more details.

+2
source

(Years later), I found a library that does what I need at the time I sent the message. Akuma is a library for demonizing Java processes. This allows you to restart the JVM with new arguments.

The difference between using this and starting a new process using bootstrap is that stdin / stdout and other file descriptors are automatically split.

+1
source

As others have noted, this is usually only possible with a bootstrap program (Java or another language) that calls the main JVM with the correct parameters.

So, are you sure this is necessary? You specify "maximum heap size". If you refer to the -Xmx option: this is just a limit that a VM can never exceed. This does not mean that the virtual machine will really use it a lot, it will do less if possible.

That way, you can always set -Xmx to the maximum that the system can handle, and let the JVM decide how much it really needs. Why do you think you need to install it dynamically?

0
source

Dynamic tuning -Xmx, for example, would be very useful for managing projected system resources (primarily for tracking) for long work sessions. Of course, one of the many consequences is an increase / increase in GC overhead.

I know several large server machines running dozens and dozens of JVMs with a bunch of 1G +. If these battery lives could have their high water mark reduced back during low usage, you could manage your system resources much better.

0
source

Source: https://habr.com/ru/post/1439634/


All Articles