问题
How I can use async EJB's and asking for result with Future object ? Can anyone show me by a complete example.
回答1:
Before EJB 3.1,If you want to execute an asynchronous processing you had to use JMS and a MDB,In EJB 3.1, you can use a simple session EJB with the @Asynchronous annotation on the method which must be called asynchronously.
@Stateless
@Remote(HelloEjbAsynchronousRemote.class)
public class HelloEjbAsynchronous implements HelloEjbAsynchronousRemote {
@Asynchronous
@Override
public Future<String> ejbAsynchronousSayHello(String name){
If your method has a return value, your method has to return an AsyncResult object which is an implementation of Future.
return new AsyncResult<String>("Hello "+name);
来源:https://stackoverflow.com/questions/11573663/using-ejb-with-future-object