简体   繁体   中英

how different is JVM thread from tomcat threads and do they have a common pool which maps to kernel threads

i am trying to figure out how threading works as a whole when i run a spring boot application, how do thread scheduling works at each level till the code is executed in processor. what are restrictions on thread pool count at each level.

starting from the beginning,

  1. Newer version of intel processor supports hyper-threading so the no of threads that can execute parallelly is twice the no of core. but what is the restriction on no of kernel threads that can run concurrently? i mean what is the limit on wait queue.

  2. JVM threads and tomcat threads are mapped to kernel threads in order to execute. Is there some common threadPool from which JVM threads and tomcat threads are created? if so what is the restriction on this.

  3. Does JVM do thread scheduling in order to manage its threadPool.

please refer an article or a book, which can help me understand.

There is nothing special about Tomcat threads: they are the same as every other thread in the JVM. In most modern OSs and JVMs, a JVM thread maps directly to an OS thread (which cam be implemented differently depending upon the OS, of course).

Newer version of intel processor supports hyper-threading so the no of threads that can execute parallelly is twice the no of core. but what is the restriction on no of kernel threads that can run concurrently? i mean what is the limit on wait queue.

There are no limits on the wait queue AFAIK.

JVM threads and tomcat threads are mapped to kernel threads in order to execute. Is there some common threadPool from which JVM threads and tomcat threads are created? if so what is the restriction on this.

Any Java program can start any number of threads (unless it's running under s SecurityManager). Since you are using Spring Boot, I assume there is no SM in play. If you run (vanilla) Tomcat under a SM, Tomcat runs itself as an unrestricted player in the game and only the web applications are effectively sandboxed. In any of the above cases, Tomcat is not constrained.

However, Tomcat will respect the configuration it's been given. If you say that you want a thread pool with a maximum size of 100, then Tomcat will not start any more than 100 threads to service requests. (Tomcat runs a few threads in the background for housekeeping tasks, but the number is very low. The bulk of threads created by Tomcat will be for request-processing.)

Each <Connector> by default gets its own thread pool. You can configure all your <Connector> s to use a shared thread pool. Those thread pools can be controlled in terms of the maximum number of connections, etc. See the Tomcat User's Guide 's section on Connectors and the Tomcat Configuration Reference 's sections on Connectors for details.

Does JVM do thread scheduling in order to manage its threadPool.

The JVM usually delegates this to the OS.

please refer an article or a book, which can help me understand.

If you want all the details, there is always The Java Language Specification .

EDIT 2019-07-22

The mapping from Java threads to OS threads is completely handled by the JVM. Tomcat can have no effect on it whatsoever. So everything below the Java-thread concept must be researched in the context of the exact JVM in use, the exact OS in use, and how they work together to ultimately get your code executed. What I'm trying to say here is that, without a ton of additional information, your question is unanswerable .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM