Search code examples
javajsfjavabeansicefaces

Long Running Task in Java EE WebApp + icefaces


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:

  1. Create a stateless, asynchronous EJB which creates a response object and processes the request
  2. Persist the response object after each step
  3. 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

Solution

  • 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

    • store it on database accessible from both tiers ( sql, JNDI, LDAP - better solution would be key-value store , like redis - if you got it )
    • use some messaging to deposit state of processing on web tier side
    • store state in a hash it on EJB tier side, and provide another SLSB method to rtrieve this state

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