110

I am developing application server using spring boot app but now I want to know what is the default maximum (client request) thread pool size in spring and how can I customize that value?

Yu Hao
  • 119,891
  • 44
  • 235
  • 294
sagar
  • 1,269
  • 2
  • 10
  • 10

2 Answers2

152

Assuming that you're using embedded Tomcat, Spring Boot provides a property to control the size of the client request thread pool. Its default value is zero which leaves Tomcat to use its default of 200. If you're using Spring Boot 2.3 or later, this property is named server.tomcat.threads.max. In earlier versions of Spring Boot, the property is named server.tomcat.max-threads.

To customise the size of this thread pool you should specify a non-zero value for the property in your application.properties or application.yml file.

Andy Wilkinson
  • 108,729
  • 24
  • 257
  • 242
  • 6
    Thank you. So what if server gets a more requests than that is specified in application.properties or application.yml. I have a assumption that it holds the request is it? – sagar Aug 21 '14 at 05:36
  • 40
    [..request requires a thread for the duration of that request. If more simultaneous requests are received than can be handled by the currently available request processing threads, additional threads will be created up to the configured maximum (the value of the maxThreads attribute). If still more simultaneous requests are received, they are stacked up inside the server socket created by the Connector, up to the configured maximum (the value of the acceptCount attribute). Any further simultaneous requests will receive "connection refused" errors, until resources are available to process them. – Marouane Gazanayi Feb 09 '16 at 13:00
  • 2
    It's extracted from here: https://tomcat.apache.org/tomcat-7.0-doc/config/http.html – Marouane Gazanayi Feb 09 '16 at 13:01
  • Could you help here ? http://stackoverflow.com/questions/43181576/threadlocal-using-as-context-information-for-rest-api-with-spring-boot –  Apr 03 '17 at 18:43
  • what will be the maximum thread pool size that tomcat can handle under different jvm sizes? any way to calculate that value – Anushka Ekanayake Apr 24 '17 at 05:04
  • Can these properties be controlled with code outside of the normal properties file? – jocull Jun 18 '18 at 14:08
  • 1
    @jocull Yes, they can by using a `ConnectorCustomizer`. Here's how Boot does it: https://github.com/spring-projects/spring-boot/blob/master/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/TomcatWebServerFactoryCustomizer.java#L184-L193. – Andy Wilkinson Jun 18 '18 at 14:16
  • @AndyWilkinson, I have set mine to server.tomcat.max-threads=1 but it just keeps on growing to a point that it crashers my server. – Artanis Zeratul Dec 07 '18 at 13:59
  • If it’s growing unbounded it sounds like you have a different problem. If the default configuration was being used the number of threads would be capped at 200. I’d recommend asking a new question with a minimal examplenthat reproduces the behaviour you have described. – Andy Wilkinson Dec 07 '18 at 18:36
  • from springboot 2.3 use server.tomcat.threads.max – Nibras Dec 20 '22 at 14:02
56

As server.tomcat.max-threads is deprecated since Springboot 2.3, now use server.tomcat.threads.max in your Spring application.properties. Default is 200.

Zon
  • 18,610
  • 7
  • 91
  • 99
  • 1
    you should point for which version of spring boot it is acceptible. for 2.2.1 this is wrong. – Simon Logic Mar 10 '21 at 09:12
  • 2
    I think the best is to consult the official reference: https://docs.spring.io/spring-boot/docs/current/reference/html/application-properties.html#appendix.application-properties.web – IlyaP Oct 28 '22 at 19:28