简体   繁体   中英

Tomcat NIO thread pools

I understand java NIO (channels, selector, ..). I would like to understand Tomcat NIO better so that i can configure thread pools of Tomcat appropriately from Spring boot.

Can someone please explain what is the purpose of each thread pool and how do these work in relevance to java NIO? it would be helpful it you can also point out which thread pool is used during say processing of HTTP requests.

Some Tomcat8 thread pools observed during thread dumps:

http-nio-<port>-Acceptor (usually 1 or 2 threads)
http-nio-<port>-ClientPoller-<index> (usually 2)
http-nio-<port>-exec-<index> (usually 10)
NioBlockingSelector.BlockPoller-<index> (usually 2)

http-nio--exec- (usually 10) => This can be controlled by setting "server.tomcat.max-threads=10" in application.properties. If its set to 1, then you see only one thread http-nio--exec-1.

I am too trying to find out other thread pools.

The proper solution with Spring and Tomcat would be to use 2 properties:

server.tomcat.max-threads=200 # Maximum amount of worker threads.
server.tomcat.min-spare-threads=10 # Minimum amount of worker threads

If you change the server.tomcat.max-thread below the server.tomcat.min-spare-threads , then you will have as many thread as the max-thread property.

If you change the server.tomcat.min-spare-threads , then you will have as many thread as specified.

For instance, if you set to this: server.tomcat.min-spare-threads=15 , then you will have 15 http-nio-8080-exec-*

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