I have a Spring Boot application in which everytime API call is made, I am creating an ExecutorService with fixedThreadPool size of 5 threads and passing around 500 tasks to CompletableFuture to run Async. I am using this for a migration of lakhs of data.
As I started the migration, initially API was working fine and each API Call ( Basically code logic + ThreadPool Creation + Jobs Assignment to threads ) was taking around just 200 ms or so. But as API calls increased and new threadpools kept on creating, I can see gradual increase in time being taken to Create the thread Pool and assign the jobs, as a result API response time went till 4 secs. Note : After the jobs are done, i am shutting down the executor service in finally block.
Question :
- Can multiple creation create overhead to the application and do those pools keep on piling up?
- Wont there be any automatic garbage collection to this ?
- Will there be any limit to how many pools get created ?
- And what could be causing this time delay ..
I can add further clarifications based on specific queries..