本文整理汇总了Java中java.lang.management.MemoryUsage.from方法的典型用法代码示例。如果您正苦于以下问题:Java MemoryUsage.from方法的具体用法?Java MemoryUsage.from怎么用?Java MemoryUsage.from使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.lang.management.MemoryUsage
的用法示例。
在下文中一共展示了MemoryUsage.from方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: badTypeCompositeData
import java.lang.management.MemoryUsage; //导入方法依赖的package包/类
public static void badTypeCompositeData() throws Exception {
final int K = 1024;
final Object[] values = {
new Integer(5 * K),
new Long(1 * K),
new Long(10 * K),
new Long(2 * K),
"Dummy",
"Dummy",
};
CompositeType muct =
new CompositeType("MyMemoryUsageCompositeType",
"CompositeType for MemoryUsage",
memoryUsageItemNames,
memoryUsageItemNames,
badMUItemTypes);
CompositeData cd =
new CompositeDataSupport(muct,
memoryUsageItemNames,
values);
try {
MemoryUsage u = MemoryUsage.from(cd);
} catch (IllegalArgumentException e) {
System.out.println("Expected exception: " +
e.getMessage());
return;
}
throw new RuntimeException(
"IllegalArgumentException not thrown");
}
示例2: badNameCompositeData
import java.lang.management.MemoryUsage; //导入方法依赖的package包/类
public static void badNameCompositeData() throws Exception {
final int K = 1024;
final Object[] values = {
new Long(5 * K),
new Long(1 * K),
new Long(10 * K),
new Long(2 * K),
"Dummy",
"Dummy",
};
CompositeType muct =
new CompositeType("MyMemoryUsageCompositeType",
"CompositeType for MemoryUsage",
badMUItemNames,
badMUItemNames,
memoryUsageItemTypes);
CompositeData cd =
new CompositeDataSupport(muct,
badMUItemNames,
values);
try {
MemoryUsage u = MemoryUsage.from(cd);
} catch (IllegalArgumentException e) {
System.out.println("Expected exception: " +
e.getMessage());
return;
}
throw new RuntimeException(
"IllegalArgumentException not thrown");
}
示例3: getUsage
import java.lang.management.MemoryUsage; //导入方法依赖的package包/类
public static MemoryUsage getUsage(CompositeData cd) {
CompositeData usageData = (CompositeData) cd.get(USAGE);
return MemoryUsage.from(usageData);
}
示例4: createGoodCompositeData
import java.lang.management.MemoryUsage; //导入方法依赖的package包/类
public static void createGoodCompositeData() throws Exception {
final int K = 1024;
// these values are synchronized with the item names
final Object[] values = {
new Long(5 * K), // committed
new Long(1 * K), // init
new Long(10 * K), // max
new Long(2 * K), // used
"Dummy",
"Dummy",
};
CompositeType muct =
new CompositeType("MyMemoryUsageCompositeType",
"CompositeType for MemoryUsage",
memoryUsageItemNames,
memoryUsageItemNames,
memoryUsageItemTypes);
CompositeData cd =
new CompositeDataSupport(muct,
memoryUsageItemNames,
values);
MemoryUsage u = MemoryUsage.from(cd);
if (u.getInit() != ((Long) values[INIT]).longValue()) {
throw new RuntimeException("init = " + u.getInit() +
" expected = " + values[INIT]);
}
if (u.getUsed() != ((Long) values[USED]).longValue()) {
throw new RuntimeException("used = " + u.getUsed() +
" expected = " + values[USED]);
}
if (u.getCommitted() != ((Long) values[COMMITTED]).longValue()) {
throw new RuntimeException("committed = " + u.getCommitted() +
" expected = " + values[COMMITTED]);
}
if (u.getMax() != ((Long) values[MAX]).longValue()) {
throw new RuntimeException("max = " + u.getMax() +
" expected = " + values[MAX]);
}
System.out.println(u);
}