下面列出了java.lang.management.MemoryUsage#from ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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");
}
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");
}
public long getEdenFree()
throws JMException
{
CompositeData data
= (CompositeData) _mbeanServer.getAttribute(getEdenName(), "Usage");
MemoryUsage usage = MemoryUsage.from(data);
return usage.getMax() - usage.getUsed();
}
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");
}
public long getEdenCommitted()
throws JMException
{
CompositeData data
= (CompositeData) _mbeanServer.getAttribute(getEdenName(), "Usage");
MemoryUsage usage = MemoryUsage.from(data);
return usage.getCommitted();
}
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");
}
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");
}
public long getTenuredMax()
throws JMException
{
CompositeData data
= (CompositeData) _mbeanServer.getAttribute(getTenuredName(), "Usage");
MemoryUsage usage = MemoryUsage.from(data);
return usage.getMax();
}
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");
}
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");
}
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");
}
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);
}
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);
}
public static MemoryUsage getUsage(CompositeData cd) {
CompositeData usageData = (CompositeData) cd.get(USAGE);
return MemoryUsage.from(usageData);
}
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);
}
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);
}
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);
}
public static MemoryUsage getUsage(CompositeData cd) {
CompositeData usageData = (CompositeData) cd.get(USAGE);
return MemoryUsage.from(usageData);
}
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);
}
public static MemoryUsage getUsage(CompositeData cd) {
CompositeData usageData = (CompositeData) cd.get(USAGE);
return MemoryUsage.from(usageData);
}