You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2022/02/02 19:35:02 UTC

[tomcat] branch main updated: Correct a regression in the fix for BZ 65454

This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/main by this push:
     new 084ca27  Correct a regression in the fix for BZ 65454
084ca27 is described below

commit 084ca270fafb9b0cc3dfac1c9d56e78115dd4d5a
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Wed Feb 2 19:34:39 2022 +0000

    Correct a regression in the fix for BZ 65454
    
    Additional updates for new package for ThreadPoolExecutor
    https://bz.apache.org/bugzilla/show_bug.cgi?id=65454
---
 .../catalina/loader/WebappClassLoaderBase.java       | 14 ++++++++++----
 .../org/apache/tomcat/util/net/AbstractEndpoint.java | 20 ++++++++++++--------
 webapps/docs/changelog.xml                           |  5 +++++
 3 files changed, 27 insertions(+), 12 deletions(-)

diff --git a/java/org/apache/catalina/loader/WebappClassLoaderBase.java b/java/org/apache/catalina/loader/WebappClassLoaderBase.java
index 8649c5c..85710d8 100644
--- a/java/org/apache/catalina/loader/WebappClassLoaderBase.java
+++ b/java/org/apache/catalina/loader/WebappClassLoaderBase.java
@@ -57,7 +57,6 @@ import java.util.Map.Entry;
 import java.util.NoSuchElementException;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.CopyOnWriteArrayList;
-import java.util.concurrent.ThreadPoolExecutor;
 import java.util.jar.Attributes;
 import java.util.jar.Attributes.Name;
 import java.util.jar.Manifest;
@@ -80,6 +79,7 @@ import org.apache.tomcat.util.IntrospectionUtils;
 import org.apache.tomcat.util.compat.JreCompat;
 import org.apache.tomcat.util.res.StringManager;
 import org.apache.tomcat.util.security.PermissionCheck;
+import org.apache.tomcat.util.threads.ThreadPoolExecutor;
 
 /**
  * Specialized web application class loader.
@@ -1871,16 +1871,22 @@ public abstract class WebappClassLoaderBase extends URLClassLoader
                         }
 
                         // "java.util.concurrent" code is in public domain,
-                        // so all implementations are similar
+                        // so all implementations are similar including our
+                        // internal fork.
                         if (target != null && target.getClass().getCanonicalName() != null &&
-                                target.getClass().getCanonicalName().equals(
-                                        "java.util.concurrent.ThreadPoolExecutor.Worker")) {
+                                (target.getClass().getCanonicalName().equals(
+                                        "org.apache.tomcat.util.threads.ThreadPoolExecutor.Worker") ||
+                                        target.getClass().getCanonicalName().equals(
+                                                "java.util.concurrent.ThreadPoolExecutor.Worker"))) {
                             Field executorField = target.getClass().getDeclaredField("this$0");
                             executorField.setAccessible(true);
                             Object executor = executorField.get(target);
                             if (executor instanceof ThreadPoolExecutor) {
                                 ((ThreadPoolExecutor) executor).shutdownNow();
                                 usingExecutor = true;
+                            } else if (executor instanceof java.util.concurrent.ThreadPoolExecutor) {
+                                ((java.util.concurrent.ThreadPoolExecutor) executor).shutdownNow();
+                                usingExecutor = true;
                             }
                         }
                     } catch (SecurityException | NoSuchFieldException | IllegalArgumentException |
diff --git a/java/org/apache/tomcat/util/net/AbstractEndpoint.java b/java/org/apache/tomcat/util/net/AbstractEndpoint.java
index 832119a..e2875c1 100644
--- a/java/org/apache/tomcat/util/net/AbstractEndpoint.java
+++ b/java/org/apache/tomcat/util/net/AbstractEndpoint.java
@@ -682,12 +682,12 @@ public abstract class AbstractEndpoint<S,U> {
     public void setMinSpareThreads(int minSpareThreads) {
         this.minSpareThreads = minSpareThreads;
         Executor executor = this.executor;
-        if (internalExecutor && executor instanceof java.util.concurrent.ThreadPoolExecutor) {
+        if (internalExecutor && executor instanceof ThreadPoolExecutor) {
             // The internal executor should always be an instance of
-            // j.u.c.ThreadPoolExecutor but it may be null if the endpoint is
-            // not running.
+            // org.apache.tomcat.util.threads.ThreadPoolExecutor but it may be
+            // null if the endpoint is not running.
             // This check also avoids various threading issues.
-            ((java.util.concurrent.ThreadPoolExecutor) executor).setCorePoolSize(minSpareThreads);
+            ((ThreadPoolExecutor) executor).setCorePoolSize(minSpareThreads);
         }
     }
     public int getMinSpareThreads() {
@@ -709,12 +709,12 @@ public abstract class AbstractEndpoint<S,U> {
     public void setMaxThreads(int maxThreads) {
         this.maxThreads = maxThreads;
         Executor executor = this.executor;
-        if (internalExecutor && executor instanceof java.util.concurrent.ThreadPoolExecutor) {
+        if (internalExecutor && executor instanceof ThreadPoolExecutor) {
             // The internal executor should always be an instance of
-            // j.u.c.ThreadPoolExecutor but it may be null if the endpoint is
-            // not running.
+            // org.apache.tomcat.util.threads.ThreadPoolExecutor but it may be
+            // null if the endpoint is not running.
             // This check also avoids various threading issues.
-            ((java.util.concurrent.ThreadPoolExecutor) executor).setMaximumPoolSize(maxThreads);
+            ((ThreadPoolExecutor) executor).setMaximumPoolSize(maxThreads);
         }
     }
     public int getMaxThreads() {
@@ -904,6 +904,8 @@ public abstract class AbstractEndpoint<S,U> {
         if (executor != null) {
             if (executor instanceof ThreadPoolExecutor) {
                 return ((ThreadPoolExecutor) executor).getPoolSize();
+            } else if (executor instanceof java.util.concurrent.ThreadPoolExecutor) {
+                return ((java.util.concurrent.ThreadPoolExecutor) executor).getPoolSize();
             } else if (executor instanceof ResizableExecutor) {
                 return ((ResizableExecutor) executor).getPoolSize();
             } else {
@@ -924,6 +926,8 @@ public abstract class AbstractEndpoint<S,U> {
         if (executor != null) {
             if (executor instanceof ThreadPoolExecutor) {
                 return ((ThreadPoolExecutor) executor).getActiveCount();
+            } else if (executor instanceof java.util.concurrent.ThreadPoolExecutor) {
+                return ((java.util.concurrent.ThreadPoolExecutor) executor).getActiveCount();
             } else if (executor instanceof ResizableExecutor) {
                 return ((ResizableExecutor) executor).getActiveCount();
             } else {
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 49c54ee..72776da 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -122,6 +122,11 @@
   <subsection name="Coyote">
     <changelog>
       <fix>
+        Correct a regression in the fix for <bug>65454</bug> that meant that
+        <code>minSpareThreads</code> and <code>maxThreads</code> settings were
+        ignored when the Connector used an internal executor. (markt)
+      </fix>
+      <fix>
         <bug>65848</bug>: Revert the change that attempted to align the
         behaviour of client certificate authentication with NIO or NIO2 with
         OpenSSL for TLS between MacOS and Linux/Windows as the root cause was

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