felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r936174 - /felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/system/VMStatPlugin.java
Date Wed, 21 Apr 2010 06:45:54 GMT
Author: fmeschbe
Date: Wed Apr 21 06:45:53 2010
New Revision: 936174

URL: http://svn.apache.org/viewvc?rev=936174&view=rev
Log:
FELIX-2291 Catch NoSuchMethodError on pre-1.4 Java runtimes which do not have the Runtime.availableProcessors
method

Modified:
    felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/system/VMStatPlugin.java

Modified: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/system/VMStatPlugin.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/system/VMStatPlugin.java?rev=936174&r1=936173&r2=936174&view=diff
==============================================================================
--- felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/system/VMStatPlugin.java
(original)
+++ felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/system/VMStatPlugin.java
Wed Apr 21 06:45:53 2010
@@ -206,11 +206,17 @@ public class VMStatPlugin extends Simple
             json.put( "jvm", System.getProperty( "java.vm.name" ) + "(build " + System.getProperty(
"java.vm.version" )
                 + ", " + System.getProperty( "java.vm.info" ) + ")" );
             json.put( "shutdownTimer", shutdownTimer );
-            json.put( "processors", Runtime.getRuntime().availableProcessors() );
             json.put( "mem_total", totalMem );
             json.put( "mem_free", freeMem );
             json.put( "mem_used", usedMem );
             json.put( "shutdownType", shutdownType );
+
+            // only add the processors if the number is available
+            final int processors = getAvailableProcessors();
+            if ( processors > 0 )
+            {
+                json.put( "processors", processors );
+            }
         }
         catch ( JSONException e )
         {
@@ -228,4 +234,24 @@ public class VMStatPlugin extends Simple
     {
         return ( StartLevel ) getService( START_LEVEL_NAME );
     }
+
+
+    /**
+     * Returns the number of processor available on Java 1.4 and newer runtimes.
+     * If the Runtime.availableProcessors() method is not available, this
+     * method returns -1.
+     */
+    private int getAvailableProcessors()
+    {
+        try
+        {
+            return Runtime.getRuntime().availableProcessors();
+        }
+        catch ( Throwable t )
+        {
+            // NoSuchMethodError on pre-1.4 runtimes
+        }
+
+        return -1;
+    }
 }



Mime
View raw message