Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference reading system properties with RuntimeMXBean instance and System.getProperties

Tags:

java

what is the difference between reading system properties in this different ways

RuntimeMXBean RuntimemxBean = ManagementFactory.getRuntimeMXBean();
Object value =  RuntimemxBean.getSystemProperties();
System.out.println(value);

AND

Properties systemProperties = System.getProperties();
systemProperties.list(System.out);
like image 402
Eric Martinez Avatar asked Oct 22 '22 03:10

Eric Martinez


1 Answers

At least in Sun JVM, the result should be the same as RuntimeMXBean.getSystemProperties() calls System.getProperties() internally.

public Map<String, String> getSystemProperties() {
    Properties localProperties = System.getProperties();
    HashMap localHashMap = new HashMap();

    Set localSet = localProperties.stringPropertyNames();
    for (String str1 : localSet) {
      String str2 = localProperties.getProperty(str1);
      localHashMap.put(str1, str2);
    }

    return localHashMap;
}

The difference is you can use RuntimeMXBean from a remote JVM (see 2) to obtain its system properties.

like image 128
fglez Avatar answered Oct 26 '22 23:10

fglez