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.
You have to explicitly call scheduler.initialize()
after setting all properties but before returning the scheduler.
See full working test case here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With