使用RuntimeMXBean实例和System.getProperties读取系统属性的差异

Eri*_*nez 5 java

以这种不同的方式阅读系统属性之间的区别是什么

RuntimeMXBean RuntimemxBean = ManagementFactory.getRuntimeMXBean();
Object value =  RuntimemxBean.getSystemProperties();
System.out.println(value);
Run Code Online (Sandbox Code Playgroud)

Properties systemProperties = System.getProperties();
systemProperties.list(System.out);
Run Code Online (Sandbox Code Playgroud)

fgl*_*lez 3

RuntimeMXBean.getSystemProperties()至少在Sun JVM中,结果应该与内部调用相同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;
}
Run Code Online (Sandbox Code Playgroud)

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