简体   繁体   English

JVM线程与tomcat线程有何不同,它们是否具有映射到内核线程的公共池

[英]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. 我试图弄清楚运行Spring Boot应用程序时线程是如何整体工作的,线程调度在每个级别如何工作,直到在处理器中执行代码为止。 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. 较新版本的Intel处理器支持超线程,因此可以并行执行的线程数是内核数的两倍。 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. JVM线程和tomcat线程被映射到内核线程以便执行。 Is there some common threadPool from which JVM threads and tomcat threads are created? 是否有一些常见的threadPool可从中创建JVM线程和tomcat线程? if so what is the restriction on this. 如果是这样,对此有何限制?

  3. Does JVM do thread scheduling in order to manage its threadPool. JVM是否执行线程调度以管理其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. Tomcat线程没有什么特别之处:它们与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). 在大多数现代OS和JVM中,JVM线程直接映射到OS线程(当然,具体取决于OS的实现方式也不同)。

Newer version of intel processor supports hyper-threading so the no of threads that can execute parallelly is twice the no of core. 较新版本的Intel处理器支持超线程,因此可以并行执行的线程数是内核数的两倍。 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. 等待队列AFAIK没有限制。

JVM threads and tomcat threads are mapped to kernel threads in order to execute. JVM线程和tomcat线程被映射到内核线程以便执行。 Is there some common threadPool from which JVM threads and tomcat threads are created? 是否有一些常见的threadPool可从中创建JVM线程和tomcat线程? if so what is the restriction on this. 如果是这样,对此有何限制?

Any Java program can start any number of threads (unless it's running under s SecurityManager). 任何Java程序都可以启动任意数量的线程(除非它在SecurityManager下运行)。 Since you are using Spring Boot, I assume there is no SM in play. 由于您使用的是Spring Boot,因此我假设没有SM在玩。 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. 如果在SM下运行(普通)Tomcat,则Tomcat本身将作为游戏中不受限制的播放器运行,并且仅对Web应用程序进行了有效的沙盒处理。 In any of the above cases, Tomcat is not constrained. 在以上任何一种情况下,Tomcat均不受限制。

However, Tomcat will respect the configuration it's been given. 但是,Tomcat将遵守它的配置。 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. 如果您说您想要一个最大为100的线程池,那么Tomcat不会启动超过100个线程来服务请求。 (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.) (Tomcat在后台运行一些线程来执行家务任务,但是数量很少。Tomcat创建的大部分线程将用于请求处理。)

Each <Connector> by default gets its own thread pool. 默认情况下,每个<Connector>都有自己的线程池。 You can configure all your <Connector> s to use a shared thread pool. 您可以将所有<Connector>配置为使用共享线程池。 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. 可以根据最大连接数等来控制这些线程池。有关详细信息,请参见《连接器》上的《 Tomcat用户指南 》部分和连接器上的《 Tomcat配置参考 》部分。

Does JVM do thread scheduling in order to manage its threadPool. JVM是否执行线程调度以管理其threadPool。

The JVM usually delegates this to the OS. JVM通常将此委托给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 . 如果您需要所有详细信息,总有《 Java语言规范》

EDIT 2019-07-22 编辑2019-07-22

The mapping from Java threads to OS threads is completely handled by the JVM. 从Java线程到OS线程的映射完全由JVM处理。 Tomcat can have no effect on it whatsoever. Tomcat对此没有任何影响。 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. 因此,必须在使用的确切JVM,使用的确切OS以及它们如何协同工作以最终执行代码的上下文中研究Java线程概念以下的所有内容。 What I'm trying to say here is that, without a ton of additional information, your question is unanswerable . 我要在这里说的是,没有大量其他信息, 您的问题将无法回答

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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