admin管理员组文章数量:1122826
I have built a SpringBoot application with REST APIs, One of these multithreaded APIs is implemented using executor service.
ExecutorService service = Executors.newFixedThreadPool(threadPoolSize);
I have built a SpringBoot application with REST APIs, One of these multithreaded APIs is implemented using executor service.
ExecutorService service = Executors.newFixedThreadPool(threadPoolSize);
Now my question is that if a thread is created to handle a request, when this thread gets free, can it be used to handle the multithreading tasks (handled by executor service), aka can these two share same thread pools. There is no other configuration done wrt executor service, or tomcat.
Also if you guys can link some articles or other resources to better understand multithreading in springboot and java, it would be of great help. I am new to these concepts.
Share Improve this question edited Nov 25, 2024 at 21:28 Mohamed amine ben hassen 8701 gold badge11 silver badges29 bronze badges asked Nov 21, 2024 at 19:04 Jahnvi TanwarJahnvi Tanwar 234 bronze badges 3- This won't be a good idea because one request could block all other requests from being handled when it consumes enough of the other http acceptor threads - a classic DoS. – SpaceTrucker Commented Nov 21, 2024 at 20:50
- Not clear what you're asking. Is it that if a thread created outside of the executor can still execute tasks submitted to the executor? in that case, no. – forty-two Commented Nov 21, 2024 at 22:34
- For more clarification my question is: are the threads created by tomcat to handle API requests and the threads handled by executor service, come from the same thread pool, or two separate thread pools are maintained in Java ? – Jahnvi Tanwar Commented Dec 1, 2024 at 16:32
1 Answer
Reset to default 0I think that is not good idea for handle request by using Executor service. Because Embedded tomcat which is included spring-boot-starter-web dependency can handle thread pool itself. You can just configure on application properties / yaml file.
If you want to use multiple thread, use or test another use cases for example processing huge file (at least more than 2GB).
For handle requests asynchronously, I will recommend spring-boot-flux project.
本文标签:
版权声明:本文标题:java - Can the threads handling api requests and used in multithreading inside the request belong to same thread pool, in spring 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736307874a1933461.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论