concept future interface in category ejb

appears as: Future interface
EJB 3 in Action, Second Edition

This is an excerpt from Manning's book EJB 3 in Action, Second Edition.

The use of this annotation on a class was demonstrated in listing 3.5 and on individual methods in listing 3.6. The annotation is the simple part; things start to get complicated when we look at the Future interface.

The javax.ejb.AsyncResult class was added in Java EE 6 as a convenience class for wrapping the result to be returned so that you don’t have to provide your own implementation of Future. An asynchronous method creates an instance of AsyncResult and passes in the “payload” that will be returned to the caller, as you can see in listing 3.7. While the bean is performing the long-running operation, it can find out if the task has been cancelled via the Future interface by calling the static SessionContext.wasCancelCalled() method. If the operation has been cancelled, the method should bail at this point, because the result of the operation will be ignored. The AsyncResult class makes passing back asynchronous data easy.