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

remm 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 62594a6311 Fix deadlock on startup
62594a6311 is described below

commit 62594a6311ae186286dffa463523476a5704c6f3
Author: remm <r...@apache.org>
AuthorDate: Thu May 19 10:25:50 2022 +0200

    Fix deadlock on startup
    
    PR515. Involving only certain utility executor configurations. This
    should use its own lock object as the main object is already synced
    during the whole startup.
    Submitted by Han Li.
---
 java/org/apache/catalina/core/StandardServer.java | 29 +++++++++++++----------
 webapps/docs/changelog.xml                        |  4 ++++
 2 files changed, 20 insertions(+), 13 deletions(-)

diff --git a/java/org/apache/catalina/core/StandardServer.java 
b/java/org/apache/catalina/core/StandardServer.java
index b2684b56f0..c0c472f613 100644
--- a/java/org/apache/catalina/core/StandardServer.java
+++ b/java/org/apache/catalina/core/StandardServer.java
@@ -187,6 +187,7 @@ public final class StandardServer extends 
LifecycleMBeanBase implements Server {
      * Utility executor with scheduling capabilities.
      */
     private ScheduledThreadPoolExecutor utilityExecutor = null;
+    private final Object utilityExecutorLock = new Object();
 
     /**
      * Utility executor wrapper.
@@ -431,19 +432,21 @@ public final class StandardServer extends 
LifecycleMBeanBase implements Server {
     }
 
 
-    private synchronized void reconfigureUtilityExecutor(int threads) {
-        // The ScheduledThreadPoolExecutor doesn't use MaximumPoolSize, only 
CorePoolSize is available
-        if (utilityExecutor != null) {
-            utilityExecutor.setCorePoolSize(threads);
-        } else {
-            ScheduledThreadPoolExecutor scheduledThreadPoolExecutor =
-                    new ScheduledThreadPoolExecutor(threads,
-                            new TaskThreadFactory("Catalina-utility-", 
utilityThreadsAsDaemon, Thread.MIN_PRIORITY));
-            scheduledThreadPoolExecutor.setKeepAliveTime(10, TimeUnit.SECONDS);
-            scheduledThreadPoolExecutor.setRemoveOnCancelPolicy(true);
-            
scheduledThreadPoolExecutor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
-            utilityExecutor = scheduledThreadPoolExecutor;
-            utilityExecutorWrapper = new 
org.apache.tomcat.util.threads.ScheduledThreadPoolExecutor(utilityExecutor);
+    private void reconfigureUtilityExecutor(int threads) {
+        synchronized (utilityExecutorLock) {
+            // The ScheduledThreadPoolExecutor doesn't use MaximumPoolSize, 
only CorePoolSize is available
+            if (utilityExecutor != null) {
+                utilityExecutor.setCorePoolSize(threads);
+            } else {
+                ScheduledThreadPoolExecutor scheduledThreadPoolExecutor =
+                        new ScheduledThreadPoolExecutor(threads,
+                                new TaskThreadFactory("Catalina-utility-", 
utilityThreadsAsDaemon, Thread.MIN_PRIORITY));
+                scheduledThreadPoolExecutor.setKeepAliveTime(10, 
TimeUnit.SECONDS);
+                scheduledThreadPoolExecutor.setRemoveOnCancelPolicy(true);
+                
scheduledThreadPoolExecutor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
+                utilityExecutor = scheduledThreadPoolExecutor;
+                utilityExecutorWrapper = new 
org.apache.tomcat.util.threads.ScheduledThreadPoolExecutor(utilityExecutor);
+            }
         }
     }
 
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index c1a182402b..283029c1b5 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -120,6 +120,10 @@
         <code>clearReferencesObjectStreamClassCaches</code> when running on a
         JRE that includes a fix for the underlying memory leak. (markt)
       </fix>
+      <fix>
+        <pr>515</pr>: Avoid deadlock on startup with some utility executor
+        configurations. Submitted by Han Li. (remm)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Jasper">


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

Reply via email to