Using EJB with Future<?> object

大兔子大兔子 提交于 2020-04-07 06:05:54

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!