Spring Boot @Async method in controller is executing synchronously

后端 未结 6 1708
天涯浪人
天涯浪人 2020-12-07 18:02

My [basic] Spring Boot application accepts a request from the browser, sent via jQuery.get() and is supposed to immediately receive a response - such as \"y

6条回答
  •  执念已碎
    2020-12-07 18:12

    I had a similar issue and I had the annotations @Async and @EnableAsync in the correct beans and still the method was executing synchronously. After I checked the logs there was a warning saying that I had more than one bean of type ThreadPoolTaskExecutor and none of them called taskExecutor So...

    @Bean(name="taskExecutor")
    public ThreadPoolTaskExecutor defaultTaskExecutor() {
         ThreadPoolTaskExecutor pool = new ThreadPoolTaskExecutor();
         //Thread pool configuration
         //...
         return pool;
    }
    

    See http://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/scheduling/concurrent/ThreadPoolTaskExecutor.html for the configuration available for the thread pool.

提交回复
热议问题