0

I'm trying to get information about a jar program running, especially the heap usage. But the only informarion I get is "sun.java.command". The properties regarding the heap usage return null.

VirtualMachine test = VirtualMachine.attach("" + id); System.out.println(test.getAgentProperties());

I used the code above to get the information of the properties.

josef
  • 11
  • 4
  • You might find JMX more useful: https://docs.oracle.com/javase/tutorial/jmx/remote/ – VGR Sep 09 '19 at 13:53
  • Which “properties regarding the heap usage” are you talking about? – Holger Sep 09 '19 at 14:24
  • @Holger for example I would want to have this information: XX:MaxMetaspaceSize=256m -XX:+HeapDumpOnOutOfMemoryError -Xmx512m -Dfile.encoding=windows-**** -Duser.country=US -Duser.language=en -Duser.variant – josef Sep 10 '19 at 07:44
  • Do you want to know, how the command line looked like or do you want to know the effective settings? Command line options may get ignored for some reasons or get superseded by subsequent operations, e.g. `System.setProperty` calls, while effective settings may also reflect defaults rather than explicit settings. – Holger Sep 10 '19 at 07:58
  • @Holger I would want to know to effective settings I guess(Mb If I mistunderstand your question), to be able to see the information. I would want to program this and not just see it on the command line, as I need this to make a tool to show properties of a program. – josef Sep 10 '19 at 08:01
  • In your previous question, I gave you the link to [this answer](https://stackoverflow.com/a/19400008/2711488) in a comment. It shows the relevant operations. You have to use [`getSystemProperties()`](https://docs.oracle.com/en/java/javase/11/docs/api/jdk.attach/com/sun/tools/attach/VirtualMachine.html#getSystemProperties()) instead of `getAgentProperties()`. This covers the `-D` kind of setting. It also shows how to get JMX beans to access the memory statistics, which provides some of the other settings. For more, you need the `GarbageCollectorMXBean` and the `HotSpotDiagnosticMXBean`. – Holger Sep 10 '19 at 08:15
  • @Holger alright will look up the thread in detail, thank your for you help – josef Sep 10 '19 at 08:20

0 Answers0