Hi Team ,
Management of start and stop might be arrested Regards Koti On Thu, 4 May 2023, 19:12 , <ma...@apache.org> wrote: > 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 > > commit 4b097bf2e9075e9e2949ec5aa410cba3c2b85374 > 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 | 13 +++++++--- > 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 | 5 ++++ > 5 files changed, 41 insertions(+), 30 deletions(-) > > diff --git a/java/org/apache/catalina/connector/Connector.java > b/java/org/apache/catalina/connector/Connector.java > index c9200e20ca..dac7fdd642 100644 > --- a/java/org/apache/catalina/connector/Connector.java > +++ b/java/org/apache/catalina/connector/Connector.java > @@ -992,9 +992,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) { > @@ -1035,6 +1032,11 @@ public class Connector extends LifecycleMBeanBase { > > setState(LifecycleState.STARTING); > > + // Configure the utility executor before starting the protocol > handler > + if (service != null) { > + > protocolHandler.setUtilityExecutor(service.getServer().getUtilityExecutor()); > + } > + > try { > protocolHandler.start(); > } catch (Exception e) { > @@ -1060,6 +1062,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 (service != null) { > + protocolHandler.setUtilityExecutor(null); > + } > } > > > diff --git a/java/org/apache/catalina/core/ContainerBase.java > b/java/org/apache/catalina/core/ContainerBase.java > index 784c9032ef..a7e7c69a4a 100644 > --- a/java/org/apache/catalina/core/ContainerBase.java > +++ b/java/org/apache/catalina/core/ContainerBase.java > @@ -787,13 +787,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 > @@ -819,6 +812,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(); > @@ -925,6 +920,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 > @@ -954,11 +955,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 80b5026fed..a4383f2503 100644 > --- a/java/org/apache/catalina/core/StandardServer.java > +++ b/java/org/apache/catalina/core/StandardServer.java > @@ -901,6 +901,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 > @@ -961,6 +967,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(); > @@ -975,12 +989,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 > @@ -1014,14 +1022,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 131799a300..ebdac44cee 100644 > --- a/webapps/docs/changelog.xml > +++ b/webapps/docs/changelog.xml > @@ -134,6 +134,11 @@ > file locking protection or the manager servlet. Submitted > by Jack Shirazi. (remm) > </fix> > + <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"> > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org > For additional commands, e-mail: dev-h...@tomcat.apache.org > >