I'm developing a restful Web service that runs as a servlet (using blocking IO) in Jetty. Figuring out the optimal setting for max threads seems hard.
Is there a researched formula for deciding the max number of threads from some easily measurable characteristics of the rest of the setup?
By default, Tomcat sets maxThreads to 200, which represents the maximum number of threads allowed to run at any given time.
Web Container is responsible for instantiating the servlet or creating a new thread to handle the request. Its the job of Web Container to get the request and response to the servlet. The container creates multiple threads to process multiple requests to a single servlet. Servlets don't have a main() method.
Maximum number of threads in Spring Boot Application max-threads to control how many threads you want to allow. This is set to 0 by default which means- use the Tomcat default which is 200 .
Method 1 – /proc This is the easiest way to see the thread count of any active process on a Linux machine. proc command exports text file of process and system hardware information, such as CPU, interrupts, memory, disk, etc. The above example is having one thread per process.
Very simple and primitive one:
max_number_of_threads = number_of_CPUs * C
Where C depends on other factors of your application :-)
Ask yourself following questions:
Usually I set C rather low, e.g. 2 - 10.
No there is not. Keep you number of threads limited and under control so you not exceed system resources, Java's limit is usually around 100-200 live threads.
Good way to do it is by using Executors from java.util.concurrent.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With