5

以这种不同的方式读取系统属性有什么区别

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

Properties systemProperties = System.getProperties();
systemProperties.list(System.out);
4

1 回答 1

3

至少在 Sun JVM 中,结果应该与内部RuntimeMXBean.getSystemProperties()调用相同System.getProperties()

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

不同之处在于您可以使用RuntimeMXBean远程 JVM(参见 2)来获取其系统属性。

于 2012-11-07T16:45:22.500 回答