I have an SpringBoot application where I have allowed at most 45 concurrent requests.
Now, 1 request in its journey calls 16 external services in parallel using
threadPool A. So keeping the average case and worst case in mind, I kept following configurations for it :
ThreadPoolTaskExecutor A = new ThreadPoolTaskExecutor(); A.setCorePoolSize(400); A.setMaxPoolSize(1000); A.setQueueCapacity(10); A.setThreadNamePrefix("async-executor"); A.initialize();
My expectations here were that at most 45*16 = 720 threads will be used. But on running load test, I observe that threads kept on getting open (checked in thread dump), and after few minutes it started giving RejectedExecutionException.
RejectedExecutionException Task ServiceX rejected from org.springframework.scheduling.concurrent. ThreadPoolTaskExecutor$1@4221a19e[Running, pool size = 1000, active threads = 2, queued tasks = 10, completed tasks = 625216]
I wanted to know what I am missing here? Why am I getting rejection?