Java EE WebApp 中的长时间运行任务 +冰面
我对 Java EE 的了解不多,但目前正在学习。
我提出了一个项目,其中涉及由用户调用的长时间运行的任务(长达几分钟)。该任务由几个步骤组成。当然我想向用户展示进度。
该项目使用 Java EE 以及 JPA、JSF 和 Icefaces。它在 Glassfish 上运行。
一位经验丰富的同事向我建议了以下模式:
- 创建一个无状态、异步 EJB,它创建响应对象并处理请求
- 在每个步骤后保留响应对象
- 在支持 bean 中,查询并显示响应对象
这效果很好。我唯一的问题是更新状态站点以反映进度。目前,我通过每 x 秒重新加载一次简单的 JavaScript 页面来完成此操作。
您知道一种方法/模式来反映从无状态 ejb 到 jsf 支持 bean 的当前步骤吗? 或者,我更喜欢这样,你知道一种方法来每 x 秒查询一个支持 bean 的值吗?
编辑:
我知道 Icefaces 推送机制,但我希望状态更新站点与计算 EJB 分离,原因如下:
- 由于用户离开站点,支持 bean 可能已经被销毁并稍后返回以获取结果
- 多个会话,因此一个用户可能存在多个 bean
- 具有简洁的设计
I don't have much knowledge on Java EE but am currently learning it.
I've come up with a project which involves a long running task (up to several minutes) invoked by the user. The task consists of several steps. Of course I would like to show the progress to the user.
The project uses Java EE with JPA, JSF and Icefaces. It runs on Glassfish.
An experienced colleague adviced the following pattern to me:
- Create a stateless, asynchronous EJB which creates a response object and processes the request
- Persist the response object after each step
- In the backing bean, query and display the response object
This works well. My only problem is to update the status site to mirror the progress. Currently I am doing this with a simple JavaScript page reload every x seconds.
Do you know a way/pattern to reflect the current step from the stateless ejb to the jsf backing bean?
Or, and I would prefer that, do you know a way to query the value of a backing bean every x seconds?
Edit:
I am aware of the Icefaces push mechanism, but I want the status update site to be decoupled from the calculation EJB for the following reasons:
- The backing bean might already be destroyed because the user left the site and return later to fetch the result
- Multiple sessions and therefore multiple beans may exist for one user
- Having a clean design
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
有多种选项可以传回此信息。如果 EJB 位于同一个 JVM 中,
您也可以使用一些单例 Map 并在某个键(会话 ID)下存储进度。
如果不是这种情况,您将需要一些共享状态或通信。有几个选项
您的选择并不容易 - 所有这些解决方案都以不同的方式进行。
There are several options to pass back this information. If EJB is living in the same JVM,
you may as well use some singleton Map and store progress under certain key (session ID)
If this is not the case, you will need some shared state or comminucation. There are several options
Your choice is not easy - all of these solution suckin a different ways.
我使用线程轮询模型结合 ProgressBar 组件来完成此操作。
I accomplished this using a threaded polling model in conjunction with a ProgressBar component.
当您使用icefaces时,您可以使用 ICEpush 机制来渲染您的更新。
As you are using icefaces you could use the ICEpush mechanism for rendering your updates.