summaryrefslogtreecommitdiff
path: root/examples/gnu
diff options
context:
space:
mode:
authorAndrew John Hughes <gnu_andrew@member.fsf.org>2006-07-01 13:47:20 +0000
committerAndrew John Hughes <gnu_andrew@member.fsf.org>2006-07-01 13:47:20 +0000
commit1eec7134085cd736739b5238a1034d1951bd7b25 (patch)
tree7e1c00de2c960f8a99665e0d146783c2ebe54f4a /examples/gnu
parent2f65b82887113c7b39c34f415ec690b20074bd06 (diff)
downloadclasspath-1eec7134085cd736739b5238a1034d1951bd7b25.tar.gz
2006-07-01 Andrew John Hughes <gnu_andrew@member.fsf.org>
* examples/gnu/classpath/examples/management/TestClassLoading.java, * examples/gnu/classpath/examples/management/TestOS.java, * examples/gnu/classpath/examples/management/TestRuntime.java, * examples/gnu/classpath/examples/management/TestThread.java: New files.
Diffstat (limited to 'examples/gnu')
-rw-r--r--examples/gnu/classpath/examples/management/TestClassLoading.java41
-rw-r--r--examples/gnu/classpath/examples/management/TestOS.java37
-rw-r--r--examples/gnu/classpath/examples/management/TestRuntime.java54
-rw-r--r--examples/gnu/classpath/examples/management/TestThread.java118
4 files changed, 250 insertions, 0 deletions
diff --git a/examples/gnu/classpath/examples/management/TestClassLoading.java b/examples/gnu/classpath/examples/management/TestClassLoading.java
new file mode 100644
index 000000000..113a4f258
--- /dev/null
+++ b/examples/gnu/classpath/examples/management/TestClassLoading.java
@@ -0,0 +1,41 @@
+/* TestClassLoading.java -- Tests the class loading bean.
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath examples.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA. */
+
+package gnu.classpath.examples.management;
+
+import java.lang.management.ClassLoadingMXBean;
+import java.lang.management.ManagementFactory;
+
+public class TestClassLoading
+{
+ public static void main(String[] args)
+ {
+ ClassLoadingMXBean bean = ManagementFactory.getClassLoadingMXBean();
+ System.out.println("Bean: " + bean);
+ System.out.println("Loaded classes: " + bean.getLoadedClassCount());
+ System.out.println("Unloaded classes: " + bean.getUnloadedClassCount());
+ System.out.println("Total loaded classes: " + bean.getTotalLoadedClassCount());
+ boolean verbosity = bean.isVerbose();
+ System.out.println("Verbose class output: " + (verbosity ? "yes" : "no"));
+ System.out.println("Changing verbose setting...");
+ bean.setVerbose(!verbosity);
+ System.out.println("Verbose class output: " + (bean.isVerbose() ? "yes" : "no"));
+ }
+}
diff --git a/examples/gnu/classpath/examples/management/TestOS.java b/examples/gnu/classpath/examples/management/TestOS.java
new file mode 100644
index 000000000..a13e514f8
--- /dev/null
+++ b/examples/gnu/classpath/examples/management/TestOS.java
@@ -0,0 +1,37 @@
+/* TestOS.java -- Tests the OS bean.
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath examples.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA. */
+
+package gnu.classpath.examples.management;
+
+import java.lang.management.ManagementFactory;
+import java.lang.management.OperatingSystemMXBean;
+
+public class TestOS
+{
+ public static void main(String[] args)
+ {
+ OperatingSystemMXBean osBean = ManagementFactory.getOperatingSystemMXBean();
+ System.out.println("Bean: " + osBean);
+ System.out.println("OS Name: " + osBean.getName());
+ System.out.println("OS Version: " + osBean.getVersion());
+ System.out.println("Architecture: " + osBean.getArch());
+ System.out.println("Processors: " + osBean.getAvailableProcessors());
+ }
+}
diff --git a/examples/gnu/classpath/examples/management/TestRuntime.java b/examples/gnu/classpath/examples/management/TestRuntime.java
new file mode 100644
index 000000000..2a629ca83
--- /dev/null
+++ b/examples/gnu/classpath/examples/management/TestRuntime.java
@@ -0,0 +1,54 @@
+/* TestRuntime.java -- Tests the runtime bean.
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath examples.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA. */
+
+package gnu.classpath.examples.management;
+
+import java.lang.management.ManagementFactory;
+import java.lang.management.RuntimeMXBean;
+
+import java.util.Date;
+
+public class TestRuntime
+{
+
+ public static void main(String[] args)
+ {
+ RuntimeMXBean vmBean = ManagementFactory.getRuntimeMXBean();
+ System.out.println("Bean: " + vmBean);
+ boolean bootClassPath = vmBean.isBootClassPathSupported();
+ System.out.println("Boot Class Path Supported: " + bootClassPath);
+ if (bootClassPath)
+ System.out.println("Boot Class Path: " + vmBean.getBootClassPath());
+ System.out.println("Class Path: " + vmBean.getClassPath());
+ System.out.println("Input Arguments: " + vmBean.getInputArguments());
+ System.out.println("Library Path: " + vmBean.getLibraryPath());
+ System.out.println("Management Spec. Version: " + vmBean.getManagementSpecVersion());
+ System.out.println("Name: " + vmBean.getName());
+ System.out.println("Spec Name: " + vmBean.getSpecName());
+ System.out.println("Spec Vendor: " + vmBean.getSpecVendor());
+ System.out.println("Spec Version: " + vmBean.getSpecVersion());
+ System.out.println("Start Time: " + new Date(vmBean.getStartTime()));
+ System.out.println("System Properties: " + vmBean.getSystemProperties());
+ System.out.println("Uptime: " + vmBean.getUptime() + "ms");
+ System.out.println("VM Name: " + vmBean.getVmName());
+ System.out.println("VM Vendor: " + vmBean.getVmVendor());
+ System.out.println("VM Version: " + vmBean.getVmVersion());
+ }
+}
diff --git a/examples/gnu/classpath/examples/management/TestThread.java b/examples/gnu/classpath/examples/management/TestThread.java
new file mode 100644
index 000000000..e49776ce2
--- /dev/null
+++ b/examples/gnu/classpath/examples/management/TestThread.java
@@ -0,0 +1,118 @@
+/* TestThread.java -- Tests the thread bean.
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath examples.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA. */
+
+package gnu.classpath.examples.management;
+
+import java.lang.management.ManagementFactory;
+import java.lang.management.ThreadInfo;
+import java.lang.management.ThreadMXBean;
+
+import java.util.Arrays;
+
+public class TestThread
+{
+
+ public static void main(String[] args)
+ {
+ ThreadMXBean bean = ManagementFactory.getThreadMXBean();
+ System.out.println("Bean: " + bean);
+ System.out.println("Monitor deadlocked threads: " + bean.findMonitorDeadlockedThreads());
+ long[] ids = bean.getAllThreadIds();
+ System.out.println("Live thread ids: " + Arrays.toString(ids));
+ boolean currentTimeMonitoring = bean.isCurrentThreadCpuTimeSupported();
+ System.out.println("Current thread CPU time monitoring supported: " + currentTimeMonitoring);
+ if (currentTimeMonitoring)
+ {
+ boolean timeEnabled = bean.isThreadCpuTimeEnabled();
+ System.out.println("Is time monitoring enabled... " +
+ (timeEnabled ? "yes" : "no"));
+ if (!timeEnabled)
+ {
+ System.out.println("Enabling...");
+ bean.setThreadCpuTimeEnabled(true);
+ timeEnabled = bean.isThreadCpuTimeEnabled();
+ System.out.println("Should now be enabled... " +
+ (timeEnabled ? "yes" : "no"));
+ }
+ if (timeEnabled)
+ {
+ System.out.println("Current thread CPU time: "
+ + bean.getCurrentThreadCpuTime()
+ + "ns");
+ System.out.println("Current thread user time: "
+ + bean.getCurrentThreadUserTime()
+ + "ns");
+ }
+ }
+ System.out.println("Daemon thread count: " + bean.getDaemonThreadCount());
+ System.out.println("Peak thread count: " + bean.getPeakThreadCount());
+ System.out.println("Resetting...");
+ bean.resetPeakThreadCount();
+ System.out.println("Peak thread count: " + bean.getPeakThreadCount());
+ System.out.println("Thread count: " + bean.getThreadCount());
+ boolean timeMonitoring = bean.isThreadCpuTimeSupported();
+ System.out.println("Thread CPU time monitoring supported: " + timeMonitoring);
+ if (timeMonitoring)
+ {
+ for (int a = 0; a < ids.length; ++a)
+ {
+ System.out.println("Thread " + a
+ + " CPU time: "
+ + bean.getThreadCpuTime(ids[a]) + "ns");
+ System.out.println("Thread "
+ + a + " user time: "
+ + bean.getThreadUserTime(ids[a]) + "ns");
+ }
+ }
+ System.out.println("Current thread info: "
+ + bean.getThreadInfo(Thread.currentThread().getId()));
+ System.out.println("All thread info: " + Arrays.toString(bean.getThreadInfo(ids)));
+ System.out.println("Total started threads: " + bean.getTotalStartedThreadCount());
+ boolean contentionMonitoring = bean.isThreadContentionMonitoringSupported();
+ System.out.println("Thread contention monitoring supported: " + contentionMonitoring);
+ if (contentionMonitoring)
+ {
+ boolean contentionEnabled = bean.isThreadContentionMonitoringEnabled();
+ System.out.println("Thread contention monitoring shouldn't be enabled... " +
+ (contentionEnabled ? "but it is" : "true"));
+ if (!contentionEnabled)
+ {
+ System.out.println("Enabling...");
+ bean.setThreadContentionMonitoringEnabled(true);
+ contentionEnabled = bean.isThreadContentionMonitoringEnabled();
+ System.out.println("Should now be enabled... " +
+ (contentionEnabled ? "it is" : "nope"));
+ }
+ if (contentionEnabled)
+ {
+ ThreadInfo[] info = bean.getThreadInfo(ids);
+ for (int a = 0; a < info.length; ++a)
+ {
+ System.out.println("Blocked time for thread "
+ + info[a].getThreadId() + ": "
+ + info[a].getBlockedTime() + "ms");
+ System.out.println("Waited time for thread "
+ + info[a].getThreadId() + ": "
+ + info[a].getWaitedTime() + "ms");
+ }
+ }
+ }
+ }
+}