本文整理匯總了Java中java.lang.management.RuntimeMXBean.getSystemProperties方法的典型用法代碼示例。如果您正苦於以下問題:Java RuntimeMXBean.getSystemProperties方法的具體用法?Java RuntimeMXBean.getSystemProperties怎麽用?Java RuntimeMXBean.getSystemProperties使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.lang.management.RuntimeMXBean
的用法示例。
在下文中一共展示了RuntimeMXBean.getSystemProperties方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: beforeClass
import java.lang.management.RuntimeMXBean; //導入方法依賴的package包/類
@BeforeClass
public static void beforeClass() throws Exception {
// Print detail on jvm so we know what is different should below test fail.
RuntimeMXBean b = ManagementFactory.getRuntimeMXBean();
LOG.info("name=" + b.getName());
LOG.info("specname=" + b.getSpecName());
LOG.info("specvendor=" + b.getSpecVendor());
LOG.info("vmname=" + b.getVmName());
LOG.info("vmversion=" + b.getVmVersion());
LOG.info("vmvendor=" + b.getVmVendor());
Map<String, String> p = b.getSystemProperties();
LOG.info("properties=" + p);
}
示例2: runTest
import java.lang.management.RuntimeMXBean; //導入方法依賴的package包/類
private static void runTest() throws Exception {
RuntimeMXBean mbean = ManagementFactory.getRuntimeMXBean();
// Print all system properties
Map<String,String> props = mbean.getSystemProperties();
printProperties(props);
// Add new system properties
System.setProperty(KEY1, VALUE1);
System.setProperty(KEY2, VALUE2);
Map<String,String> props1 = mbean.getSystemProperties();
String value1 = props1.get(KEY1);
if (value1 == null || !value1.equals(VALUE1)) {
throw new RuntimeException(KEY1 + " property found" +
" with value = " + value1 +
" but expected to be " + VALUE1);
}
String value2 = props1.get(KEY2);
if (value2 == null || !value2.equals(VALUE2)) {
throw new RuntimeException(KEY2 + " property found" +
" with value = " + value2 +
" but expected to be " + VALUE2);
}
String value3 = props1.get(KEY3);
if (value3 != null) {
throw new RuntimeException(KEY3 + " property found" +
" but should not exist" );
}
// Add new system properties but are not Strings
Properties sp = System.getProperties();
sp.put(KEY3, VALUE3);
sp.put(KEY4, VALUE4);
Map<String,String> props2 = mbean.getSystemProperties();
// expect the system properties returned should be
// same as the one before adding KEY3 and KEY4
if (!props1.equals(props2)) {
throw new RuntimeException("Two copies of system properties " +
"are expected to be equal");
}
System.out.println("Test passed.");
}