在 JSF 中单击按钮异步调用长时间运行的进程 [英] Calling a long running process asynchronously on a button click in 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() {
// ...
}
}
另见:
- 是否安全在 JSF 托管 bean 中启动一个新线程?
- 服务器如何将异步更改推送到由 JSF 创建的 HTML 页面?
这篇关于在 JSF 中单击按钮异步调用长时间运行的进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!