Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Async ThreadPoolTaskScheduler not initialized

Tags:

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.

like image 571
small_ticket Avatar asked Jan 16 '17 08:01

small_ticket


1 Answers

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

See full working test case here.

like image 86
Yaroslav Stavnichiy Avatar answered Oct 02 '22 21:10

Yaroslav Stavnichiy