I have created a spring boot application which will take job requests and run them in background. These job requests are so intensive that they gonna take 4-5 hours if they are processed by single thread. Internally these job requests have separate smaller tasks which are around 300-400. So I have created a task executor to process them in parallel. It worked like charm and finished everything in 35 minutes. But problem came when another job is running parallel to this job. Now it is taking 2 hours for same job. Initially, I thought may be one job is taking all threads and making other job wait. So in order to solve this I have created another executor and assigned them to each job. But no improvement.
By the way, the internal tasks are internally calling databases.
Below is the configuration of task executors and how I am using on methods.
@Bean(name = "taskExecutor")
public Executor threadPoolTaskExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(100);
executor.setMaxPoolSize(200);
executor.setQueueCapacity(200);
executor.setThreadNamePrefix("Thread1-");
executor.initialize();
return executor;
}
@Bean(name = "exTaskExecutor")
public Executor exThreadPoolTaskExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(20);
executor.setMaxPoolSize(30);
executor.setQueueCapacity(100);
executor.setThreadNamePrefix("Thread2-");
executor.initialize();
return executor;
}
@Async("taskExecutor")
public void job1()
//do something
}
@Async("exTaskExecutor")
public void job2()
//do something
}
//database connections
spring.datasource.hikari.connectionTimeout=60000
spring.datasource.hikari.idleTimeout=600000
spring.datasource.hikari.maxLifetime=1800000
spring.datasource.hikari.autoCommit=true
spring.datasource.hikari.maximumPoolSize=120
spring.datasource.hikari.connection-test-query: SELECT 1 FROM DUAL
I am not getting where the problem is? Is it in task executors or HikariCP? All I can see from logs is threads from two executors are not running in parallel at any point of time. Any help or alternative way is highly appreciated.