Spring Async ThreadPoolTaskScheduler not initialized

small_ticket :

I'm trying to use Async annotation in Spring but I'm getting

java.lang.IllegalStateException: ThreadPoolTaskScheduler not initialized

error, when I try to run the method marked as Async. The following is the configuration for Async:

@EnableScheduling
@EnableAsync
@Configuration 
public class SchedulingConfiguration implements AsyncConfigurer{

    @Override
    public Executor getAsyncExecutor() {
        ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
        scheduler.setPoolSize(10);
        return scheduler;
    }

}

and the following is the declaration of async method.

@Async
@Transactional(value = "baseTransactionManager", isolation = Isolation.READ_COMMITTED)
public void foo(Bar bar) {// some code here}

What am I missing in here?

Thanks in advance.

Yaroslav Stavnichiy :

You have to explicitly call scheduler.initialize() after setting all properties but before returning the scheduler.

See full working test case here.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=448575&siteId=1