1 |
781 |
jeremybenn |
/* TestMemoryPool.java -- Tests the memory pool beans.
|
2 |
|
|
Copyright (C) 2006 Free Software Foundation, Inc.
|
3 |
|
|
|
4 |
|
|
This file is part of GNU Classpath examples.
|
5 |
|
|
|
6 |
|
|
GNU Classpath is free software; you can redistribute it and/or modify
|
7 |
|
|
it under the terms of the GNU General Public License as published by
|
8 |
|
|
the Free Software Foundation; either version 2, or (at your option)
|
9 |
|
|
any later version.
|
10 |
|
|
|
11 |
|
|
GNU Classpath is distributed in the hope that it will be useful, but
|
12 |
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 |
|
|
General Public License for more details.
|
15 |
|
|
|
16 |
|
|
You should have received a copy of the GNU General Public License
|
17 |
|
|
along with GNU Classpath; see the file COPYING. If not, write to the
|
18 |
|
|
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
19 |
|
|
02110-1301 USA. */
|
20 |
|
|
|
21 |
|
|
package gnu.classpath.examples.management;
|
22 |
|
|
|
23 |
|
|
import java.lang.management.ManagementFactory;
|
24 |
|
|
import java.lang.management.MemoryPoolMXBean;
|
25 |
|
|
import java.util.Arrays;
|
26 |
|
|
import java.util.Iterator;
|
27 |
|
|
|
28 |
|
|
public class TestMemoryPool
|
29 |
|
|
{
|
30 |
|
|
|
31 |
|
|
/**
|
32 |
|
|
* 1mb in bytes
|
33 |
|
|
*/
|
34 |
|
|
private static final int MB = 1 << 20;
|
35 |
|
|
|
36 |
|
|
public static void main(String[] args)
|
37 |
|
|
{
|
38 |
|
|
Iterator beans = ManagementFactory.getMemoryPoolMXBeans().iterator();
|
39 |
|
|
while (beans.hasNext())
|
40 |
|
|
{
|
41 |
|
|
MemoryPoolMXBean bean = (MemoryPoolMXBean) beans.next();
|
42 |
|
|
System.out.println("Bean: " + bean);
|
43 |
|
|
System.out.println("Name: " + bean.getName());
|
44 |
|
|
System.out.println("Collection usage: " + bean.getCollectionUsage());
|
45 |
|
|
boolean collectionUsage = bean.isCollectionUsageThresholdSupported();
|
46 |
|
|
System.out.println("Collection usage threshold supported: "
|
47 |
|
|
+ collectionUsage);
|
48 |
|
|
if (collectionUsage)
|
49 |
|
|
{
|
50 |
|
|
System.out.println("Collection usage threshold: "
|
51 |
|
|
+ bean.getCollectionUsageThreshold());
|
52 |
|
|
System.out.println("Setting collection usage threshold to 1MB ("
|
53 |
|
|
+ MB + " bytes)");
|
54 |
|
|
bean.setCollectionUsageThreshold(MB);
|
55 |
|
|
System.out.println("Collection usage threshold: "
|
56 |
|
|
+ bean.getCollectionUsageThreshold());
|
57 |
|
|
System.out.println("Collection usage threshold count: "
|
58 |
|
|
+ bean.getCollectionUsageThresholdCount());
|
59 |
|
|
System.out.println("Collection usage threshold exceeded: "
|
60 |
|
|
+ (bean.isCollectionUsageThresholdExceeded()
|
61 |
|
|
? "yes" : "no"));
|
62 |
|
|
}
|
63 |
|
|
System.out.println("Memory manager names: "
|
64 |
|
|
+ Arrays.toString(bean.getMemoryManagerNames()));
|
65 |
|
|
System.out.println("Peak usage: " + bean.getPeakUsage());
|
66 |
|
|
System.out.println("Current usage: " + bean.getUsage());
|
67 |
|
|
System.out.println("Resetting peak usage...");
|
68 |
|
|
bean.resetPeakUsage();
|
69 |
|
|
System.out.println("Peak usage: " + bean.getPeakUsage());
|
70 |
|
|
System.out.println("Current usage: " + bean.getUsage());
|
71 |
|
|
boolean usage = bean.isUsageThresholdSupported();
|
72 |
|
|
System.out.println("Usage threshold supported: " + usage);
|
73 |
|
|
if (usage)
|
74 |
|
|
{
|
75 |
|
|
System.out.println("Usage threshold: "
|
76 |
|
|
+ bean.getUsageThreshold());
|
77 |
|
|
System.out.println("Setting usage threshold to 1MB ("
|
78 |
|
|
+ MB + " bytes)");
|
79 |
|
|
bean.setUsageThreshold(MB);
|
80 |
|
|
System.out.println("Usage threshold: "
|
81 |
|
|
+ bean.getUsageThreshold());
|
82 |
|
|
System.out.println("Usage threshold count: "
|
83 |
|
|
+ bean.getUsageThresholdCount());
|
84 |
|
|
System.out.println("Usage threshold exceeded: "
|
85 |
|
|
+ (bean.isUsageThresholdExceeded()
|
86 |
|
|
? "yes" : "no"));
|
87 |
|
|
}
|
88 |
|
|
System.out.println("Valid: " + (bean.isValid() ? "yes" : "no"));
|
89 |
|
|
}
|
90 |
|
|
}
|
91 |
|
|
}
|