This adds an example class for each of the existing management
beans in java.lang.management.  They basically just list the properties
of each bean; a good way of testing your VM's support for the new features.

Changelog:

2006-07-01  Andrew John Hughes  <[EMAIL PROTECTED]>
        
        * 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.

-- 
Andrew :-)

Please avoid sending me Microsoft Office (e.g. Word, PowerPoint) attachments.
See http://www.fsf.org/philosophy/no-word-attachments.html

If you use Microsoft Office, support movement towards the end of vendor lock-in:
http://opendocumentfellowship.org/petition/

"Value your freedom, or you will lose it, teaches history. 
`Don't bother us with politics' respond those who don't want to learn." 
-- Richard Stallman

Escape the Java Trap with GNU Classpath!
http://www.gnu.org/philosophy/java-trap.html
public class gcj extends Freedom implements Java { ... }
Index: examples/gnu/classpath/examples/management/TestClassLoading.java
===================================================================
RCS file: examples/gnu/classpath/examples/management/TestClassLoading.java
diff -N examples/gnu/classpath/examples/management/TestClassLoading.java
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ examples/gnu/classpath/examples/management/TestClassLoading.java    1 Jul 
2006 13:42:10 -0000
@@ -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"));
+  }
+}
Index: examples/gnu/classpath/examples/management/TestOS.java
===================================================================
RCS file: examples/gnu/classpath/examples/management/TestOS.java
diff -N examples/gnu/classpath/examples/management/TestOS.java
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ examples/gnu/classpath/examples/management/TestOS.java      1 Jul 2006 
13:42:10 -0000
@@ -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());
+  }
+}
Index: examples/gnu/classpath/examples/management/TestRuntime.java
===================================================================
RCS file: examples/gnu/classpath/examples/management/TestRuntime.java
diff -N examples/gnu/classpath/examples/management/TestRuntime.java
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ examples/gnu/classpath/examples/management/TestRuntime.java 1 Jul 2006 
13:42:10 -0000
@@ -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());
+  }
+}
Index: examples/gnu/classpath/examples/management/TestThread.java
===================================================================
RCS file: examples/gnu/classpath/examples/management/TestThread.java
diff -N examples/gnu/classpath/examples/management/TestThread.java
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ examples/gnu/classpath/examples/management/TestThread.java  1 Jul 2006 
13:42:10 -0000
@@ -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");
+             }
+         }
+      }
+  }
+}

Attachment: signature.asc
Description: Digital signature

Reply via email to