Spring @Async Not Working

后端 未结 11 736
北荒
北荒 2020-12-08 06:30

An @Async method in a @Service-annotated class is not being called asynchronously - it\'s blocking the thread.

I\'ve got

11条回答
  •  情话喂你
    2020-12-08 07:11

    Try below: 1. In config create bean for ThreadPoolTaskExecutor

    @Bean(name = "threadPoolTaskExecutor")
        public Executor threadPoolTaskExecutor() {
            return new ThreadPoolTaskExecutor();
        }
    

    2. In service method where @Async is used add

    @Async("threadPoolTaskExecutor")
        public void asyncMethod(){
        //do something
        }
    

    This should get @Async working.

提交回复
热议问题