EJB @Asynchronous

EJB was one of the earliest Java EE specifications. At that time, it was the specification getting the most attention and features. Now, it is slowly being replaced by CDI and integrations, with other specifications such as JTA, JPA, and so on. However, it still contains a set of useful features that you don't find elsewhere in Java EE.

EJB also has an asynchronous solution. It is more direct compared to CDI, since you can mark a method as asynchronous:

@Asynchronouspublic Future<MyResult> execute() {    return new AsyncResult<>(getResult());}

@Asynchronous requests the server to execute the task in the EJB thread pool. The method can return void, but if it needs to return a value, it must return Future. With Java 8, it is ...

Get Java EE 8 High Performance now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.