简体   繁体   中英

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?

@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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM