- Expose executors in JMX (shouldn't hurt).
authorremm <remm@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 22 Mar 2007 13:29:30 +0000 (13:29 +0000)
committerremm <remm@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 22 Mar 2007 13:29:30 +0000 (13:29 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk@521257 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/core/StandardService.java
java/org/apache/catalina/core/StandardThreadExecutor.java

index 0764c1e..42ac3cc 100644 (file)
@@ -518,6 +518,12 @@ public class StandardService
             }
         }
 
+        synchronized (executors) {
+            for ( int i=0; i<executors.size(); i++ ) {
+                executors.get(i).start();
+            }
+        }
+
         // Start our defined Connectors second
         synchronized (connectors) {
             for (int i = 0; i < connectors.length; i++) {
@@ -526,12 +532,6 @@ public class StandardService
             }
         }
         
-        synchronized (executors) {
-            for ( int i=0; i<executors.size(); i++ ) {
-                executors.get(i).start();
-            }
-        }
-
         // Notify our interested LifecycleListeners
         lifecycle.fireLifecycleEvent(AFTER_START_EVENT, null);
 
@@ -594,11 +594,27 @@ public class StandardService
             }
         }
 
+        synchronized (executors) {
+            for ( int i=0; i<executors.size(); i++ ) {
+                executors.get(i).stop();
+            }
+        }
+
         if( oname==controller ) {
             // we registered ourself on init().
             // That should be the typical case - this object is just for
             // backward compat, nobody should bother to load it explicitely
             Registry.getRegistry(null, null).unregisterComponent(oname);
+            Executor[] executors = findExecutors();
+            for (int i = 0; i < executors.length; i++) {
+                try {
+                    ObjectName executorObjectName = 
+                        new ObjectName(domain + ":type=Executor,name=" + executors[i].getName());
+                    Registry.getRegistry(null, null).unregisterComponent(executorObjectName);
+                } catch (Exception e) {
+                    // Ignore (invalid ON, which cannot happen)
+                }
+            }
         }
         
 
@@ -632,6 +648,15 @@ public class StandardService
                 this.controller=oname;
                 Registry.getRegistry(null, null)
                     .registerComponent(this, oname, null);
+                
+                Executor[] executors = findExecutors();
+                for (int i = 0; i < executors.length; i++) {
+                    ObjectName executorObjectName = 
+                        new ObjectName(domain + ":type=Executor,name=" + executors[i].getName());
+                    Registry.getRegistry(null, null)
+                        .registerComponent(executors[i], executorObjectName, null);
+                }
+                
             } catch (Exception e) {
                 log.error(sm.getString("standardService.register.failed",domain),e);
             }
index 47fe186..1b339e4 100644 (file)
@@ -155,9 +155,26 @@ public class StandardThreadExecutor implements Executor {
         lifecycle.removeLifecycleListener(listener);\r
     }\r
 \r
+    // Statistics from the thread pool\r
+    public int getActiveCount() {\r
+        return (executor != null) ? executor.getActiveCount() : 0;\r
+    }\r
 \r
-    \r
+    public long getCompletedTaskCount() {\r
+        return (executor != null) ? executor.getCompletedTaskCount() : 0;\r
+    }\r
+\r
+    public int getCorePoolSize() {\r
+        return (executor != null) ? executor.getCorePoolSize() : 0;\r
+    }\r
+\r
+    public int getLargestPoolSize() {\r
+        return (executor != null) ? executor.getLargestPoolSize() : 0;\r
+    }\r
 \r
+    public int getPoolSize() {\r
+        return (executor != null) ? executor.getPoolSize() : 0;\r
+    }\r
 \r
     // ---------------------------------------------- TaskQueue Inner Class\r
     class TaskQueue extends LinkedBlockingQueue<Runnable> {\r