Eric Martinez
Eric Martinez

Reputation: 414

difference reading system properties with RuntimeMXBean instance and System.getProperties

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);

Upvotes: 5

Views: 1006

Answers (1)

fglez
fglez

Reputation: 8552

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.

Upvotes: 3

Related Questions