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

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

问题描述

我想通过单击用 JSF 和 Java 开发的按钮来执行存储过程.执行过程大约需要 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天全站免登陆