This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 10.1.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit 9c3e2c8148a513bcd2813761632988d82126df9d Author: Mark Thomas <ma...@apache.org> AuthorDate: Thu May 4 14:41:01 2023 +0100 Move management of utility executor from init/destroy to start/stop --- java/org/apache/catalina/connector/Connector.java | 14 ++++++++--- java/org/apache/catalina/core/ContainerBase.java | 20 +++++++--------- java/org/apache/catalina/core/StandardServer.java | 28 +++++++++++----------- .../apache/catalina/ha/tcp/SimpleTcpCluster.java | 5 +++- webapps/docs/changelog.xml | 9 +++++++ 5 files changed, 46 insertions(+), 30 deletions(-) diff --git a/java/org/apache/catalina/connector/Connector.java b/java/org/apache/catalina/connector/Connector.java index f9893b992e..18e865e157 100644 --- a/java/org/apache/catalina/connector/Connector.java +++ b/java/org/apache/catalina/connector/Connector.java @@ -994,9 +994,6 @@ public class Connector extends LifecycleMBeanBase { // Initialize adapter adapter = new CoyoteAdapter(this); protocolHandler.setAdapter(adapter); - if (service != null) { - protocolHandler.setUtilityExecutor(service.getServer().getUtilityExecutor()); - } // Make sure parseBodyMethodsSet has a default if (null == parseBodyMethodsSet) { @@ -1037,9 +1034,15 @@ public class Connector extends LifecycleMBeanBase { setState(LifecycleState.STARTING); + // Configure the utility executor before starting the protocol handler + if (protocolHandler != null && service != null) { + protocolHandler.setUtilityExecutor(service.getServer().getUtilityExecutor()); + } + try { protocolHandler.start(); } catch (Exception e) { + // Includes NPE - protocolHandler will be null for invalid protocol if throwOnFailure is false throw new LifecycleException(sm.getString("coyoteConnector.protocolHandlerStartFailed"), e); } } @@ -1062,6 +1065,11 @@ public class Connector extends LifecycleMBeanBase { } catch (Exception e) { throw new LifecycleException(sm.getString("coyoteConnector.protocolHandlerStopFailed"), e); } + + // Remove the utility executor once the protocol handler has been stopped + if (protocolHandler != null) { + protocolHandler.setUtilityExecutor(null); + } } diff --git a/java/org/apache/catalina/core/ContainerBase.java b/java/org/apache/catalina/core/ContainerBase.java index 7c96f5de5e..c5bc5994a6 100644 --- a/java/org/apache/catalina/core/ContainerBase.java +++ b/java/org/apache/catalina/core/ContainerBase.java @@ -820,13 +820,6 @@ public abstract class ContainerBase extends LifecycleMBeanBase implements Contai } - @Override - protected void initInternal() throws LifecycleException { - reconfigureStartStopExecutor(getStartStopThreads()); - super.initInternal(); - } - - private void reconfigureStartStopExecutor(int threads) { if (threads == 1) { // Use a fake executor @@ -852,6 +845,8 @@ public abstract class ContainerBase extends LifecycleMBeanBase implements Contai @Override protected synchronized void startInternal() throws LifecycleException { + reconfigureStartStopExecutor(getStartStopThreads()); + // Start our subordinate components, if any logger = null; getLogger(); @@ -958,6 +953,12 @@ public abstract class ContainerBase extends LifecycleMBeanBase implements Contai if (cluster instanceof Lifecycle) { ((Lifecycle) cluster).stop(); } + + // If init fails, this may be null + if (startStopExecutor != null) { + startStopExecutor.shutdownNow(); + startStopExecutor = null; + } } @Override @@ -987,11 +988,6 @@ public abstract class ContainerBase extends LifecycleMBeanBase implements Contai parent.removeChild(this); } - // If init fails, this may be null - if (startStopExecutor != null) { - startStopExecutor.shutdownNow(); - } - super.destroyInternal(); } diff --git a/java/org/apache/catalina/core/StandardServer.java b/java/org/apache/catalina/core/StandardServer.java index 227784dbb3..5459131810 100644 --- a/java/org/apache/catalina/core/StandardServer.java +++ b/java/org/apache/catalina/core/StandardServer.java @@ -905,6 +905,12 @@ public final class StandardServer extends LifecycleMBeanBase implements Server { fireLifecycleEvent(CONFIGURE_START_EVENT, null); setState(LifecycleState.STARTING); + // Initialize utility executor + synchronized (utilityExecutorLock) { + reconfigureUtilityExecutor(getUtilityThreadsInternal(utilityThreads)); + register(utilityExecutor, "type=UtilityExecutor"); + } + globalNamingResources.start(); // Start our defined Services @@ -965,6 +971,14 @@ public final class StandardServer extends LifecycleMBeanBase implements Server { service.stop(); } + synchronized (utilityExecutorLock) { + if (utilityExecutor != null) { + utilityExecutor.shutdownNow(); + unregister("type=UtilityExecutor"); + utilityExecutor = null; + } + } + globalNamingResources.stop(); stopAwait(); @@ -979,12 +993,6 @@ public final class StandardServer extends LifecycleMBeanBase implements Server { super.initInternal(); - // Initialize utility executor - synchronized (utilityExecutorLock) { - reconfigureUtilityExecutor(getUtilityThreadsInternal(utilityThreads)); - register(utilityExecutor, "type=UtilityExecutor"); - } - // Register global String cache // Note although the cache is global, if there are multiple Servers // present in the JVM (may happen when embedding) then the same cache @@ -1018,14 +1026,6 @@ public final class StandardServer extends LifecycleMBeanBase implements Server { unregister(onameStringCache); - synchronized (utilityExecutorLock) { - if (utilityExecutor != null) { - utilityExecutor.shutdownNow(); - unregister("type=UtilityExecutor"); - utilityExecutor = null; - } - } - super.destroyInternal(); } diff --git a/java/org/apache/catalina/ha/tcp/SimpleTcpCluster.java b/java/org/apache/catalina/ha/tcp/SimpleTcpCluster.java index 83b27bddac..3f01ebf0eb 100644 --- a/java/org/apache/catalina/ha/tcp/SimpleTcpCluster.java +++ b/java/org/apache/catalina/ha/tcp/SimpleTcpCluster.java @@ -530,7 +530,6 @@ public class SimpleTcpCluster extends LifecycleMBeanBase name.append(",component=Deployer"); onameClusterDeployer = register(clusterDeployer, name.toString()); } - channel.setUtilityExecutor(Container.getService(getContainer()).getServer().getUtilityExecutor()); } @@ -548,6 +547,8 @@ public class SimpleTcpCluster extends LifecycleMBeanBase log.info(sm.getString("simpleTcpCluster.start")); } + channel.setUtilityExecutor(Container.getService(getContainer()).getServer().getUtilityExecutor()); + try { checkDefaults(); registerClusterValve(); @@ -655,6 +656,8 @@ public class SimpleTcpCluster extends LifecycleMBeanBase } catch (Exception x) { log.error(sm.getString("simpleTcpCluster.stopUnable"), x); } + + channel.setUtilityExecutor(null); } diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index ec4ba080da..8da0442af0 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -105,6 +105,15 @@ issues do not "pop up" wrt. others). --> <section name="Tomcat 10.1.10 (schultz)" rtext="in development"> + <subsection name="Catalina"> + <changelog> + <scode> + Move the management of the utility executor from the + <code>init()</code>/<code>destroy()</code> methods of components to the + <code>start()</code>/<code>stop()</code> methods. (markt) + </scode> + </changelog> + </subsection> <subsection name="Coyote"> <changelog> <update> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org