0

Tomcat architecture is comprised of the following elements: Server => Service => Engine => Host => Context tomcat architecture

When configuring a standard Tomcat server, we can configure a custom thread pool by specifying the following in our server.xml file: (below is pseudo-code)

<Server>
  <Service name="Catalina">
    <Connector port="8080"/>
    <Executor name="custom-pool" className="my.package.poolImplementation" />
    <Engine name="Catalina" defaultHost="localhost">  
      <Here be more elements />
    </Engine>
  </Service>
</Server>

(specifically, the Executor name="custom-pool" className="my.package.poolImplementation")

How do I configure Spring Boot to allow the same behaviour programmatically ?
(WITHOUT using Spring configuration files)

No matter where i searched, or how hard I tried, I couldn't find any answer or example.
Thanks in advance

  • see if u can set properties like this https://stackoverflow.com/questions/51703746/setting-relaxedquerychars-for-embedded-tomcat/51703955#51703955 – pvpkiran Mar 30 '20 at 13:39
  • @pvpkiran I have already tried, to no avail. You can refer to the tomcat instance in the way specified in that question, but you can only provide an internal tomcat executor this way: TomcatWebServer server = (TomcatWebServer)factory.getWebServer(); server.getTomcat().getService().addExecutor(/*Only allows org.apache.catalina.Executor*/); – Yonatan Alon Mar 30 '20 at 14:01

1 Answers1

1

I looked up some source code (see TomcatServletWebServerFactory.java/ServletWebServerFactoryConfiguration.java) and found a way to do that.

@Bean
public TomcatProtocolHandlerCustomizer<?> tomcatProtocolHandlerCustomizer() {
    return protocolHandler -> {
        protocolHandler.setExecutor(...);
    };
}
Joseph
  • 81
  • 6