如何在spring引导中修改tomcat8 acceptCount



如何修改tomcat默认线程数使用spring启动?当我使用spring mvc时,我可以找到tomcat,并修改conf/server.xml,然后我修改maxProcessors和acceptCount,但在spring boot中我不能这样做。

in org.apache.catalina.connector, i can't find the properties.

尝试检查您可以通过属性修改的所有内容:http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#common-application-properties

server.tomcat.max-threads = 0 # number of threads in protocol handler

否则,您将不得不亲自动手进行编程配置- http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-configure-tomcat通过提供您自己的TomcatEmbeddedServletContainerFactory

acceptCount在属性文件中不支持修改,可以通过下面的代码进行修改:

@Bean
public TomcatEmbeddedServletContainerFactory tomcatEmbeddedServletContainerFactory() {
    TomcatEmbeddedServletContainerFactory tomcatFactory = new TomcatEmbeddedServletContainerFactory();
    tomcatFactory.addConnectorCustomizers(new TomcatConnectorCustomizer() {
        @Override
        public void customize(Connector connector) {
            //tomcat default nio connector
            Http11NioProtocol handler = (Http11NioProtocol)connector.getProtocolHandler();
            //acceptCount is backlog, default value is 100, you can change which you want value in here
            handler.setBacklog(100);
        }
    });
    return tomcatFactory;
}

在当前的spring引导中,应该可以通过server.tomcat。accept-count应用程序属性,参见:https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#server-properties

相关内容

  • 没有找到相关文章

最新更新