Java EE WebApp + icefaces中的长时间运行任务 [英] Long Running Task in Java EE WebApp + icefaces

查看:355
本文介绍了Java EE WebApp + icefaces中的长时间运行任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Java EE知之甚少,但目前正在学习它。

I don't have much knowledge on Java EE but am currently learning it.

我想出了一个涉及长期任务的项目(up用户调用的几分钟)。该任务包括几个步骤。当然我想向用户展示进度。

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.

该项目使用Java EE与JPA,JSF和Icefaces。它在Glassfish上运行。

The project uses Java EE with JPA, JSF and Icefaces. It runs on Glassfish.

一位经验丰富的同事告诉我以下模式:

An experienced colleague adviced the following pattern to me:


  1. 创建一个无状态的异步EJB,它创建一个响应对象并处理请求

  2. 在每一步之后保留响应对象

  3. 在支持bean中,查询并显示响应对象

这很有效。我唯一的问题是更新状态站点以镜像进度。目前我每隔x秒就会重新加载一个简单的JavaScript页面。

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.

你知道一种方式/模式来反映从无状态ejb到jsf支持的当前步骤豆?
或者,我更喜欢这个,你知道一种每x秒查询一次支持bean值的方法吗?

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?

编辑:

我知道Icefaces推送机制,但我希望状态更新站点与计算EJB分离,原因如下:

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:


  • 支持bean可能已经被销毁,因为用户离开了网站并稍后返回以获取结果

  • 多个会话,因此一个用户可能存在多个bean

  • 设计简洁

推荐答案

有几种方法可以传回这些信息。如果EJB生活在同一个JVM中,
你也可以使用一些单例映射并在某个键下存储进度(会话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


  • 将它存储在可从两个层访问的数据库中(sql,JNDI,LDAP - 更好的解决方案是键值存储,就像redis一样 - 如果你知道的话)

  • 使用一些消息来存储web层面的处理状态

  • 将状态存储在EJB上的散列中层级方面,并提供另一种SLSB方法来缓冲这种状态

您的选择并不容易 - 所有这些解决方案都以不同的方式吸引。

Your choice is not easy - all of these solution suckin a different ways.

这篇关于Java EE WebApp + icefaces中的长时间运行任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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