Tomcat creates 25 threads by default and creates up to 200 additional threads by default.
But the question is, the number of cpu cores rarely exceeds 32.
In other words, since the number of parallel processing is around 32, I think that the maximum number of thread pools is 50.
I don't know why Tomcat made the maximum number of threads 200.
Or is it allocated a thread and queued when a request comes in, even if it cannot be processed in parallel? If so, it's very strange. Why are you allocating resources that can't even be executed to threads? (Of course, i know that if there are no threads in the thread pool, it will queue up.)
CodePudding user response:
All sorts of thing can happen during the processing of a request: files can be read, queries can be executed on a remote database server, calls can be made to remote webservices, all these operations are opportunities for a context switch to another thread.
CodePudding user response:
the number of cpu cores rarely exceeds 32.
As others have mentioned, threads provide concurrency - another thread can be executing while a different thread is in a blocked state. If all threads were in an active state, then it's true that some threads will context switch to another thread assigned to its core. But anyway, this also seems like a configurable parameter - https://www.baeldung.com/java-web-thread-pool-config
CodePudding user response:
The first time I ever wrote a multi-threaded program, it was meant to run on a computer that had only one CPU core. Threads were invented to provide concurrency, which is a broader topic than parallel processing. It can be advantageous for a web server to have more pool-worker threads than it has CPUs if those threads spend significant time in a blocked state (e.g., awaiting disk I/O.)
the number of cpu cores rarely exceeds 32
I don't know what's rare and what's not, but some computers have way more than 32. The largest of IBM's current mainframe computers can be configured with more than 200 cores.