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

少なくともSunJVMでは、結果は内部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 に答える