在JSF中单击按钮时异步调用长时间运行的进程 [英] Calling a long running process asynchronously on a button click in JSF

查看:212
本文介绍了在JSF中单击按钮时异步调用长时间运行的进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过单击用JSF和Java开发的按钮来执行存储过程。 proc执行大约需要大约30分钟。

I want to execute a stored proc by clicking on a button developed in JSF and Java. The proc takes roughly around 30 minutes in execution.

当用户点击此按钮时,他/她应该收到一条默认消息,如 -

When the user clicks on this button, s/he should get a default message like -


正在处理数据。请在60分钟后登录以检查数据。

Data is being processed. Kindly login after 60 minutes to check the data.

现在,当我们点击按钮时,UI页面挂起的时间是proc正在执行。

Now when we click on the button, the UI Page hangs for the time when the proc is getting executed.

是否有解决方法来显示此默认消息并在后端运行proc?

Is there a workaround to show this default message and run the proc in the backend?

推荐答案

只需触发 @Asynchronous EJB方法。它会触发并忘记一个单独的线程,bean动作方法将立即返回。

Just trigger an @Asynchronous EJB method. It'll fire and forget a separate thread and the bean action method will immediately return.

@Named
public class Bean {

    @EJB
    private Service service;

    public void submit() {
        service.asyncDoSomething();

        // Add message here.
    }

}





@Stateless
public class Service {

    @Asynchronous
    public void asyncDoSomething() {
        // ...
    }

}



参见:



查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆