JeffLL
JeffLL

Reputation: 1905

How to control how many threads in a Spring application?

Is it important, or even possible, to control how many threads Spring uses in, for example, a web application?

Lets say I have a Spring based REST server. Should I, or is it possible to control the number of threads Spring uses to service requests? If I deploy my app on a machine with 8 cores vs 4, should I have to configure Spring to account for the difference in cores?

Upvotes: 5

Views: 7227

Answers (1)

Stephen C
Stephen C

Reputation: 719656

The number of request threads is controlled by the web container not by Spring. For example, if you are running on Tomcat, this Q&A explains how to configure the thread pool size: https://stackoverflow.com/a/7803226/139985

Should I, or is it possible to control the number of threads used to service requests?

It is possible, but you should generally shouldn't. Let the container deal with this ... unless you have good (evidence-based!) reason to think that the container is making a poor choice. The container defaults / policy should take account of the number of available cores.

Upvotes: 1

Related Questions