简体   繁体   中英

What are impact to my spring boot application if I have task executor

I already have the configuration to config for min and max threads for my spring boot application

server.tomcat.threads.min=20
server.tomcat.threads.max=50

What are impact to my spring boot application if I have task executor in my application?

@Configuration
public class AsyncConfiguration {

@Bean("myExecutor")
public TaskExecutor getAsyncExecutor() {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(20);
    executor.setMaxPoolSize(1000);
    executor.setWaitForTasksToCompleteOnShutdown(true);
    executor.setThreadNamePrefix("Async-");
    return executor;
} }

Those are two different thread pools:

  • server.tomcat.threads.* defines the request thread pool (knowing that the Servlet API uses one thread per request)

  • myExecutor is just another pool that you could use for async operations, for instance via @EnableAsync / @Async :

By default, Spring will be searching for an associated thread pool definition: either a unique TaskExecutor bean in the context, or an Executor bean named "taskExecutor" otherwise. If neither of the two is resolvable, a SimpleAsyncTaskExecutor will be used to process async method invocations.

See also https://stackoverflow.com/a/65185737/1225328 for more details about using thread pools with Spring MVC/WebFlux.

So, to answer your actual question: both configurations don't interfere with each other:)

From my understanding

server.tomcat.threads.* : it tomcat thread pool which using for requests.

It mean If I have 2000 request coming, it only create 50 threads as my configuration.

myExcutor: it is using for Asynchronous. 

In case I want to handle for logging error in the background by using @Async annotation, If all 2000 request got fail, it create max 1000 threads. So tomcat will manage 50 threads as main threads and Spring Container will manage 1000 threads. But If I not use a custom task executor, it will use default from Spring and create 2000 new threads. In that case, my application will be slower

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