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