You need to enable JavaScript to run this app. Spring Boot嵌入式Tomcat默认HTTP线程池大小及查询方法
优惠活动
大模型
产品
解决方案
定价
更多

Spring Boot嵌入式Tomcat默认HTTP线程池大小及查询方法

嵌入式Tomcat HTTP线程池默认值及查询方法

默认线程池大小

Spring Boot 1.x、2.x、3.x官方原生版本中,嵌入式Tomcat的HTTP请求处理线程池默认最大线程数为200。如果未在application.properties或application.yml中手动配置server.tomcat.max-threads参数,应用将默认采用该值运行。

注:如果使用的是厂商二次定制的Spring Boot框架,默认值可能被修改,最终值以实际运行时生效的配置为准。

常用查询默认值的途径

  • 查看Spring Boot配置类源码
    直接查阅org.springframework.boot.autoconfigure.web.ServerProperties类的源码,其内部静态类Tomcat中明确定义了默认参数:
    private int maxThreads = 200;
    
    该值就是Spring Boot官方预置的默认最大线程数。
  • 运行时读取生效配置
    可以在应用代码中注入ServerProperties对象,直接调用对应get方法获取当前实际生效的线程池配置,示例代码如下:
    import org.springframework.boot.autoconfigure.web.ServerProperties;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Component;
    
    @Component
    public class TomcatConfigReader {
        @Autowired
        private ServerProperties serverProperties;
    
        public void printTomcatMaxThreads() {
            int maxThreads = serverProperties.getTomcat().getMaxThreads();
            System.out.println("当前Tomcat最大线程数:" + maxThreads);
        }
    }
    
    若应用开启了Actuator组件的env端点,也可以直接访问/actuator/env接口,搜索server.tomcat.max-threads字段查看生效值。
  • 查看配置元数据文件
    解压Spring Boot的autoconfigure依赖jar包,找到META-INF/spring-configuration-metadata.json文件,搜索server.tomcat.max-threads配置项,其中defaultValue字段标注的数值即为官方默认值。

内容的提问来源于stack exchange,提问作者manjosh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.18 09:39:03