This is an automated email from the ASF dual-hosted git repository. remm pushed a commit to branch 10.0.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/10.0.x by this push: new e910d44ce5 Fix deadlock on startup e910d44ce5 is described below commit e910d44ce5b2483a8c8aa181833a17624d049aad 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 d0ead54c4a..9c8069124d 100644 --- a/java/org/apache/catalina/core/StandardServer.java +++ b/java/org/apache/catalina/core/StandardServer.java @@ -191,6 +191,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. @@ -435,19 +436,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 7996901586..89df868106 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