jeudi 5 mars 2015

How to configure Spring's @Async annotation?

I've annotated a method with @Async in the hope that it will be run asynchronously. However, when I print out the thread name from the thread, it is still 'main' just as it is when I run it without the @Async annotation. It also returns about as slowly (700ms) which makes me think that it's not getting run asynchronously at all.


The bean is annotated with @Component, is getting its dependencies successfully wired in with @Autowired. I'm creating the bean with



ApplicationContext context = new AnnotationConfigApplicationContext(MyClassConfig.class);
MyClass myClass = context.getBean(MyClass.class);


Is there something I'm doing wrong?


Many thanks.


Aucun commentaire:

Enregistrer un commentaire