java – 使用RuntimeMXBean实例和System.getProperties读取系统属性的差异
发布时间:2020-05-24 03:08:31 所属栏目:Java 来源:互联网
导读:以这种不同的方式阅读系统属性之间的区别是什么 RuntimeMXBean RuntimemxBean = ManagementFactory.getRuntimeMXBean();Object value = RuntimemxBean.getSystemProperties();System.out.println(value); 和 Properties systemProperties
|
以这种不同的方式阅读系统属性之间的区别是什么 RuntimeMXBean RuntimemxBean = ManagementFactory.getRuntimeMXBean(); Object value = RuntimemxBean.getSystemProperties(); System.out.println(value); 和 Properties systemProperties = System.getProperties(); systemProperties.list(System.out); 解决方法至少在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;
}
不同之处在于您可以使用远程JVM(see 2)中的RuntimeMXBean来获取其系统属性. (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
