Spring @Async Not Working

后端 未结 11 711
北荒
北荒 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:14

    write a independent Spring configuration for asynchronous bean.
    for example:

    @Configuration
    @ComponentScan(basePackages="xxxxxxxxxxxxxxxxxxxxx")
    @EnableAsync
    public class AsyncConfig {
    
        /**
         *  used by  asynchronous event listener.
         * @return
         */
        @Bean(name = "asynchronousListenerExecutor")
        public Executor createAsynchronousListenerExecutor() {
            ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
            executor.setMaxPoolSize(100);
            executor.initialize();
            return executor;
        }
    }
    

    I overcome this problem with this situation.

提交回复
热议问题