We have a web application where our end-users will be provided with an option to schedule jobs dynamically to send some kind of reports to group of people. i.e., In UI they select date, time and timezone. Using Spring Boot Scheduler to dynamically schedule the jobs.
Present we're using a single thread-pool to asynchronously send report to group of people part of a scheduled job.
But there is a possibility that multiple people schedule jobs at same time, i.e., for instance 5 users scheduled jobs to execute tomorrow at 9AM. In this scenario, since i'm using the single thread-pool for all scheduled jobs in my application, once the first job executed then execution going to second.
So, Any possibility to use separate thread-pool for each scheduled job dynamically? it's like for each scheduled job having a thread-pool bean with request-scope. so that each job will be executed independently. or any other alternatives to achieve independent task execution.
@Scheduled(cron="0 0 1 * * *")<br>
public void schedulerTask() {<br>
List<User<User>> users = userDao.getProfiles(); // pull users from db<br>
for(User user : users) {<br>
callToAsyncMethod(user); // call to async method in scheduler<br>
}<br>
since we've multiple users pulled from db, using threadpool for asynchronous execution.<br><br>
@Async("customTaskExecutor")<br>
public void callToAsyncMethod(User user) {<br>
System.out.println("Hello " + user.getName() + ", Welcome to Scheduler Job");<br>
}<br>
@Bean("customTaskExecutor")<br>
public ThreadPoolTaskExecutor customTaskExecutor() {<br>
ThreadPoolTaskExecutor customTaskExecutor= new ThreadPoolTaskExecutor();<br>
customTaskExecutor.setCorePoolSize(5);<br>
customTaskExecutor.setMaxPoolSize(10);<br>
customTaskExecutor.setWaitForTasksToCompleteOnShutdown(true);<br>
customTaskExecutor.initialize();<br>
return customTaskExecutor;<br>
}
here all scheduler tasks indirectly referring to same threadpool for async method execution. where the bottleneck issue comes.