Resolved by defining Throttle limit: The same is defined here Spring batch multithreading: throttle-limit impact
I’m using Spring boot with Spring batch and having below TaskExecutor configuration.
@Bean
public ThreadPoolTaskExecutor getJobTaskExecutor() {
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
taskExecutor.setCorePoolSize(10);
taskExecutor.setMaxPoolSize(10);
taskExecutor.setQueueCapacity(0);
taskExecutor.setThreadNamePrefix("ProcessJob-");
taskExecutor.afterPropertiesSet();
taskExecutor.initialize();
return taskExecutor;
}
I noticed when I run batch with 20K records, some of the threads have started processing but it stops after 10 requests. However, other threads are processing properly. Can you please suggest what could be the issue? If I keep CorePoolSize=ThreadPoolSize=5 then all the threads are distributed properly.
CorePoolSize=MaxPoolSize=10 (Threads are not distributed properly)
Thread Name Count
---------------------------
Thread-ProcessJob-1 10
Thread-ProcessJob-10 4200
Thread-ProcessJob-2 10
Thread-ProcessJob-3 10
Thread-ProcessJob-4 10
Thread-ProcessJob-5 1290
Thread-ProcessJob-6 10
Thread-ProcessJob-7 4980
Thread-ProcessJob-8 4479
Thread-ProcessJob-9 4999
CorePoolSize=MaxPoolSize=5 (Threads are distributed properly)
Thread-ProcessJob-1 1199
Thread-ProcessJob-2 1201
Thread-ProcessJob-3 1214
Thread-ProcessJob-4 1211
Thread-ProcessJob-5 1209