You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Async() is not invoked in a separate thread after upgrading from 1.2.6 to 1.3.3 #5366
Not sure what changed. We have a simple setup. The Kafka task used to be started in its own executor, but after upgrading to 1.3.3 it always runs in the main thread. Anything I missed? Thanks in advance for your suggestions and helps.
` @configuration
@EnableAutoConfiguration @EnableAsync
@EnableCaching
@EnableSwagger
public class Application implements CommandLineRunner {
@Autowired
private KafkaConsumerTask kafkaTask;
public static void main(String[] args) {
new SpringApplicationBuilder(Application.class).web(true).run(args);
}
@Override
public void run(String... args) throws Exception {
kafkaTask.start();
}
You are creating a @Bean from a @Component class. That should be specified in a @Configuration class
You are injecting the service using field injection in the application class. Because it has to be instantiated quite early, I guess the framework is unable to inject the bean with the async proxy around it
If I move the task executor to the application and I move the CommandLineRunner to an inner class of the app it works.
Having said that, it's sill weird that it works in 1.2.x
Running with 4.2.5.RELEASE triggers these log messages:
2016-03-09 09:52:00.916 INFO 48097 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'kafkaConsumerTask' of type [class wguo.test.KafkaConsumerTask] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-03-09 09:52:00.917 INFO 48097 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'application' of type [class wguo.test.Application$$EnhancerBySpringCGLIB$$7d48eac9] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-03-09 09:52:00.929 INFO 48097 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'kafkaTaskExecutor'
2016-03-09 09:52:00.931 INFO 48097 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'kafkaTaskExecutor' of type [class org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
Something's changed in Spring Framework 4.2.x that means that something is triggering very early instantiation of the KafkaTaskExecutor bean, so early that it isn't eligible for bean post-processing which prevents the proxy for async method execution from being created.
Activity
wilkinsona commentedon Mar 8, 2016
Can you please provide a complete sample app that reproduces the problem?
WeipingGuo commentedon Mar 8, 2016
Thanks. I created a sample project: https://github.com/WeipingGuo/boot-async
I ran the same code using different spring boot versions. Appears that the @async is broken on 1.3.0 as it works as expected on 1.2.8
1.2.8
2016-03-08 15:07:36.613 INFO 5452 --- [aTaskExecutor-1] wguo.test.KafkaConsumerTask : starting consumer for topic testing
1.3.0
2016-03-08 18:14:20.464 INFO 7680 --- [ main] wguo.test.KafkaConsumerTask : starting consumer for topic testing
1.3.3
2016-03-08 15:08:49.341 INFO 5908 --- [ main] wguo.test.KafkaConsumerTask : starting consumer for topic testing
snicoll commentedon Mar 9, 2016
Two things:
@Beanfrom a@Componentclass. That should be specified in a@ConfigurationclassIf I move the task executor to the application and I move the
CommandLineRunnerto an inner class of the app it works.Having said that, it's sill weird that it works in 1.2.x
wilkinsona commentedon Mar 9, 2016
It also stops working with 1.2.x if you upgrade Spring Framework to 4.2.5.RELEASE
wilkinsona commentedon Mar 9, 2016
Running with 4.2.5.RELEASE triggers these log messages:
Something's changed in Spring Framework 4.2.x that means that something is triggering very early instantiation of the
KafkaTaskExecutorbean, so early that it isn't eligible for bean post-processing which prevents the proxy for async method execution from being created.wilkinsona commentedon Mar 9, 2016
I can recreate this with pure Spring Framework so this isn't a problem with Spring Boot itself. I have opened SPR-14030 to track the problem.
WeipingGuo commentedon Mar 9, 2016
Thanks for looking into it. @snicoll You are right. My bean creation was wrong, somehow it worked before.
I moved the
ThreadPoolTaskExecutorto its own class with@configuration. Now it works as charm.I guess it is not bug in Spring rather than my programming error.