Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring @Async or EJB @Asynchronous for asynchronous service invocation ?

I am working on a project using Hibernate JPA and Spring MVC, I am looking into implementing an asynchronous service, and I realized that I am getting the two annotations @Async or @Asynchronous from repectively Spring and EJB.

Everything here is pretty new for me, and I would go for the EJB @Asynchronous and see how it goes, I was wondering if one solution has an advantage over the other?

like image 373
Jako Avatar asked Jan 30 '13 19:01

Jako


1 Answers

@Async and @Asynchronous are identical in their capabilities. They both run given method in a separate thread pool and they both allow void and Future<T> result type. There is no functional different between them. The only (minor) advantage of Spring is that you have full control over underlying thread pool while with @Asynchronous this is probably configured on a container-specific basis.

If your application already uses Spring MVC, @Async seems like a natural consequence.

like image 97
Tomasz Nurkiewicz Avatar answered Oct 23 '22 09:10

Tomasz Nurkiewicz