1 /* TestMemoryPool.java -- Tests the memory pool beans.
2 Copyright (C) 2006 Free Software Foundation, Inc.
4 This file is part of GNU Classpath examples.
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)
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.
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
21 package gnu.classpath.examples.management;
23 import java.lang.management.ManagementFactory;
24 import java.lang.management.MemoryPoolMXBean;
25 import java.util.Arrays;
26 import java.util.Iterator;
28 public class TestMemoryPool
34 private static final int MB = 1 << 20;
36 public static void main(String[] args)
38 Iterator beans = ManagementFactory.getMemoryPoolMXBeans().iterator();
39 while (beans.hasNext())
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: "
50 System.out.println("Collection usage threshold: "
51 + bean.getCollectionUsageThreshold());
52 System.out.println("Setting collection usage threshold to 1MB ("
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()
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);
75 System.out.println("Usage threshold: "
76 + bean.getUsageThreshold());
77 System.out.println("Setting usage threshold to 1MB ("
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()
88 System.out.println("Valid: " + (bean.isValid() ? "yes" : "no"));