Get JVM Properties of a specific Program

1k Views Asked by At

I need to get the JVM Arguments of a specific Java Program running in the background, how do you exactly do this?

I found out, that the classes ManagementFactory and RuntimeMXBean would give me the needed result. Now I need to do this with a specific program.

Another problem is that I don't get the XMX and XMS properties when running the following code.

RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
List<String> jvmArgs = runtimeMXBean.getInputArguments();

I only get the javaagent and Dfile properties, but I also need the XMX and XMS like I said.

1

There are 1 best solutions below

4
On

A distinct non-answer:

I need to get the JVM Arguments of a specific Java Programm running in the background, how do you exactly do this?

In general, you can't.

You see, as soon as that process is running, all the parameter passed to it were "consumed", and it is totally up to that process what happens about that.

What I mean is: there is no such thing as a "universal" JVM any more in the first place. There are actually different implementations by now. Sure, they are all supposed to support the "standardised" -X options. But each and any JVM implementation is allowed to provide "its own" options and switches.

Long story short: there is no universal way to acquire "the parameters passed" from a running JVM.

If you really care about this, I suggest: write your own java wrapper script that simply logs all command line parameters into some sort of journal, ideally with a timestamp and the process ID of the "actual" java that your wrapper script invoked with those parameters.