I have three methods on my project annotated with @Scheduled, being one of them a cron expression and the other two are fixed delay. The annotations look like:
Method 1:
@Scheduled(fixedDelay = 20000)
@Async
protected void checkBrokenEngines() {
Method 2:
@Scheduled(fixedRate = 20000)
@Async
public void checkAvailableTasks() throws Exception {
Method 3:
@Scheduled(cron = "0 0 2 * * ?")
protected void deleteOldData() {
Previously I had a problem that when the checkBrokenEngines and checkAvailableTasks methods were slow to be executed, the next executions did not happen until the previous one ended. Reading the documentation and some topics here from the StackOverflow, I saw that my project had some wrong pool size settings and the methods were not annotated with async. (Async was for the next execution start even if the old one doesn't end, as this does not cause any problems in my application)
Now another problem has come up, which is my question:
When the deleteOldData() method is executed, neither of the other two methods will run until it finishes. After seeing that this method was blocking the execution of the other two, I annotated the method as async and after that, even if this method takes time to be executed, the other two are always invoked correctly within the stipulated time. Why? In my understanding, this should not happen since those methods are noted with async and the pool has enough space to execute them.
PS: deleteOldData() cannot be async. It must start just after the previous execution has been completed.
EDIT 1:
Async executor config:
@Override
public AsyncTaskExecutor getAsyncExecutor() {
log.debug("Creating Async Task Executor");
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(50);
executor.setMaxPoolSize(50);
executor.setQueueCapacity(10000);
return new ExceptionHandlingAsyncTaskExecutor(executor);
}
