tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fha...@apache.org
Subject svn commit: r783095 - in /tomcat/trunk/java/org/apache/tomcat/util/net: AprEndpoint.java JIoEndpoint.java NioEndpoint.java
Date Tue, 09 Jun 2009 18:58:25 GMT
Author: fhanik
Date: Tue Jun  9 18:58:25 2009
New Revision: 783095

URL: http://svn.apache.org/viewvc?rev=783095&view=rev
Log:
Take into account that executors can be provided, standard and non standard thread pool executors
through config or programmatically.
Hence we want to expose the correct values for curThread and curThreadBusy


Modified:
    tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java
    tomcat/trunk/java/org/apache/tomcat/util/net/JIoEndpoint.java
    tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java

Modified: tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java?rev=783095&r1=783094&r2=783095&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java Tue Jun  9 18:58:25 2009
@@ -17,10 +17,12 @@
 
 package org.apache.tomcat.util.net;
 
+import java.lang.reflect.Method;
 import java.net.InetAddress;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.concurrent.Executor;
+import java.util.concurrent.ThreadPoolExecutor;
 
 import org.apache.juli.logging.Log;
 import org.apache.juli.logging.LogFactory;
@@ -36,6 +38,7 @@
 import org.apache.tomcat.jni.SSLSocket;
 import org.apache.tomcat.jni.Socket;
 import org.apache.tomcat.jni.Status;
+import org.apache.tomcat.util.IntrospectionUtils;
 import org.apache.tomcat.util.res.StringManager;
 
 /**
@@ -538,27 +541,62 @@
         }
     }
 
-
     /**
      * Return the amount of threads that are managed by the pool.
      *
      * @return the amount of threads that are managed by the pool
      */
     public int getCurrentThreadCount() {
-        return curThreads;
+        if (executor!=null) {
+            if (executor instanceof ThreadPoolExecutor) {
+                return ((ThreadPoolExecutor)executor).getPoolSize();
+            } else {
+                try {
+                    Method m = IntrospectionUtils.findMethod(executor.getClass(), "getPoolSize",
new Class[] {}); 
+                    if (m!=null) {
+                        return ((Integer)m.invoke(executor, null)).intValue();
+                    } else {
+                        return -1;
+                    }
+                }catch (Exception ignore) {
+                    if (log.isDebugEnabled()) 
+                        log.debug("Unable to invoke getPoolSize",ignore);
+                    return -2;
+                }
+            }
+        } else {
+            return curThreads;
+        }
     }
 
-
     /**
-     * Return the amount of threads currently busy.
+     * Return the amount of threads that are in use 
      *
-     * @return the amount of threads currently busy
+     * @return the amount of threads that are in use
      */
     public int getCurrentThreadsBusy() {
-        return curThreadsBusy;
+        if (executor!=null) {
+            if (executor instanceof ThreadPoolExecutor) {
+                return ((ThreadPoolExecutor)executor).getActiveCount();
+            } else {
+                try {
+                    Method m = IntrospectionUtils.findMethod(executor.getClass(), "getActiveCount",
new Class[] {}); 
+                    if (m!=null) {
+                        return ((Integer)m.invoke(executor, null)).intValue();
+                    } else {
+                        return -1;
+                    }
+                }catch (Exception ignore) {
+                    if (log.isDebugEnabled()) 
+                        log.debug("Unable to invoke getActiveCount",ignore);
+                    return -2;
+                }
+            }
+        } else {
+            return workers!=null?curThreads - workers.size():0;
+        }
     }
-
-
+    
     /**
      * Return the state of the endpoint.
      *

Modified: tomcat/trunk/java/org/apache/tomcat/util/net/JIoEndpoint.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/JIoEndpoint.java?rev=783095&r1=783094&r2=783095&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/JIoEndpoint.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/JIoEndpoint.java Tue Jun  9 18:58:25 2009
@@ -18,11 +18,13 @@
 package org.apache.tomcat.util.net;
 
 import java.io.IOException;
+import java.lang.reflect.Method;
 import java.net.BindException;
 import java.net.InetAddress;
 import java.net.ServerSocket;
 import java.net.Socket;
 import java.util.concurrent.Executor;
+import java.util.concurrent.ThreadPoolExecutor;
 
 import org.apache.juli.logging.Log;
 import org.apache.juli.logging.LogFactory;
@@ -297,12 +299,60 @@
         return paused;
     }
     
+    /**
+     * Return the amount of threads that are managed by the pool.
+     *
+     * @return the amount of threads that are managed by the pool
+     */
     public int getCurrentThreadCount() {
-        return curThreads;
+        if (executor!=null) {
+            if (executor instanceof ThreadPoolExecutor) {
+                return ((ThreadPoolExecutor)executor).getPoolSize();
+            } else {
+                try {
+                    Method m = IntrospectionUtils.findMethod(executor.getClass(), "getPoolSize",
new Class[] {}); 
+                    if (m!=null) {
+                        return ((Integer)m.invoke(executor, null)).intValue();
+                    } else {
+                        return -1;
+                    }
+                }catch (Exception ignore) {
+                    if (log.isDebugEnabled()) 
+                        log.debug("Unable to invoke getPoolSize",ignore);
+                    return -2;
+                }
+            }
+        } else {
+            return curThreads;
+        }
     }
-    
+
+    /**
+     * Return the amount of threads that are in use 
+     *
+     * @return the amount of threads that are in use
+     */
     public int getCurrentThreadsBusy() {
-        return workers!=null?curThreads - workers.size():0;
+        if (executor!=null) {
+            if (executor instanceof ThreadPoolExecutor) {
+                return ((ThreadPoolExecutor)executor).getActiveCount();
+            } else {
+                try {
+                    Method m = IntrospectionUtils.findMethod(executor.getClass(), "getActiveCount",
new Class[] {}); 
+                    if (m!=null) {
+                        return ((Integer)m.invoke(executor, null)).intValue();
+                    } else {
+                        return -1;
+                    }
+                }catch (Exception ignore) {
+                    if (log.isDebugEnabled()) 
+                        log.debug("Unable to invoke getActiveCount",ignore);
+                    return -2;
+                }
+            }
+        } else {
+            return workers!=null?curThreads - workers.size():0;
+        }
     }
     
 

Modified: tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java?rev=783095&r1=783094&r2=783095&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java Tue Jun  9 18:58:25 2009
@@ -20,6 +20,7 @@
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
+import java.lang.reflect.Method;
 import java.net.InetAddress;
 import java.net.InetSocketAddress;
 import java.net.Socket;
@@ -726,32 +727,56 @@
      * @return the amount of threads that are managed by the pool
      */
     public int getCurrentThreadCount() {
-        final Executor executor = this.executor;
         if (executor!=null) {
-            if (executor instanceof java.util.concurrent.ThreadPoolExecutor) {
-                return ((java.util.concurrent.ThreadPoolExecutor)executor).getPoolSize();
+            if (executor instanceof ThreadPoolExecutor) {
+                return ((ThreadPoolExecutor)executor).getPoolSize();
+            } else {
+                try {
+                    Method m = IntrospectionUtils.findMethod(executor.getClass(), "getPoolSize",
new Class[] {}); 
+                    if (m!=null) {
+                        return ((Integer)m.invoke(executor, null)).intValue();
+                    } else {
+                        return -1;
+                    }
+                }catch (Exception ignore) {
+                    if (log.isDebugEnabled()) 
+                        log.debug("Unable to invoke getPoolSize",ignore);
+                    return -2;
+                }
             }
-        } 
-        return 0;
+        } else {
+            return -1;
+        }
     }
 
-
     /**
-     * Return the amount of threads currently busy.
+     * Return the amount of threads that are in use 
      *
-     * @return the amount of threads currently busy
+     * @return the amount of threads that are in use
      */
     public int getCurrentThreadsBusy() {
-        final Executor executor = this.executor;
         if (executor!=null) {
-            if (executor instanceof java.util.concurrent.ThreadPoolExecutor) {
-                return ((java.util.concurrent.ThreadPoolExecutor)executor).getPoolSize();
+            if (executor instanceof ThreadPoolExecutor) {
+                return ((ThreadPoolExecutor)executor).getActiveCount();
+            } else {
+                try {
+                    Method m = IntrospectionUtils.findMethod(executor.getClass(), "getActiveCount",
new Class[] {}); 
+                    if (m!=null) {
+                        return ((Integer)m.invoke(executor, null)).intValue();
+                    } else {
+                        return -1;
+                    }
+                }catch (Exception ignore) {
+                    if (log.isDebugEnabled()) 
+                        log.debug("Unable to invoke getActiveCount",ignore);
+                    return -2;
+                }
             }
-        } 
-        return activeSocketProcessors.get();
+        } else {
+            return -1;
+        }
     }
-
-
+    
     /**
      * Return the state of the endpoint.
      *



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message