目前网上文章写设置SpringBoot tomcat 的max_threads 的方法为:server.tomcat.max-threads=250
但是在springboot 2.3 以后已经修改为 server.tomcat.threads.max=400
老的设置会不生效
验证方法
@Configuration
public class EmbedTomcatConfig {
@Bean
WebServerFactoryCustomizer tomcatSetProtocol(){
return factory -> {
((TomcatServletWebServerFactory) factory).addConnectorCustomizers(connector -> {
ProtocolHandler protocol = connector.getProtocolHandler();
String res=String.format("Tomcat(%s) -- MaxConnection:%s;MaxThreads:%s;MinSpareThreads:%s", protocol.getClass().getName(),
((AbstractHttp11Protocol>) protocol).getMaxConnections(),
((AbstractHttp11Protocol>) protocol).getMaxThreads(),
((AbstractHttp11Protocol>) protocol).getMinSpareThreads());
System.out.println(res);
});
};
}
}
max_threads 的最佳实践为CPU内核数量的*200
默认的maxThreads 是200 (适合开发环境)
默认配置代码在:org.springframework.boot.autoconfigure.web.ServerProperties.Tomcat.Threads
参考文档:https://www.baeldung.com/java-web-thread-pool-config#1-embedded-tomcat



