Technical dilemma! Any suggestions

Discussions

EJB programming & troubleshooting: Technical dilemma! Any suggestions

  1. Technical dilemma! Any suggestions (10 messages)

    I am building a MVC based application. Here is the summary of the application:

    1-User enters some info onto a JSP page that gets passed to a Struts action.

    2-Action object calls an EJB in the back end and pass it the information.
    3-EJB makes a JMS call to another J2EE app using the IBM MQ and sends the info over and returns the msg id back to the struts action from step(2).

    Here is the interesting part:

    The UI flow needs to be transfered to another JSP page once we get a response from MQ and display it to the user but we don't know when we will receive the response (in the next 2 sec, 10 sec, 200 sec and so on)and we don't want to tell the user to come back later to complete your task.

    Here is what I came up with and it seems to be working:

    Once the action object gets the message id in step (3)it performs the following:

    a-Calls another object that runs in thread within the web container.
    b-Once the thread is started the action object forwards the control to a JSP page that displays a message to user "Please Wait....".
    c-The thread polls the MQ for response. Once it receives the response then stores it in its private data member.
    d-The JSP page keep polling the thread to determine if the response has received. If so the JSP page forwards the control to another JSP page where user can view the response and continue with their task.

    I am looking for possible suggestions where I can avoid using the thread without interrupting the user's workflow.

    Thanks.

    Threaded Messages (10)

  2. Technical dilemma! Any suggestions[ Go to top ]

    Your way sounds perfect to me. Are you facing any problem also?
  3. Technical dilemma! Any suggestions[ Go to top ]

    Initially had some problem with the Wait JSP page where it would poll the thread but thread wasn't started thus it would think the thread is done. Once I fixed this issue, it worked fine.
  4. Technical dilemma! Any suggestions[ Go to top ]

    don't know much about HTTP - meta refresh...guess I need to read up on that. Have any sample code?

    Thanks.
  5. coincidence[ Go to top ]

    Just implementing a very similar thing myself!

    response.setHeader("Refresh", "5; URL=" );

    5 is the number of seconds
    Blank URL reloads current page.
  6. coincidence[ Go to top ]

    I didn't know about that blank URL trick. Does it work in Opera, Firefox and IE? Is it documented in w3c?
  7. Sample implementation[ Go to top ]

    I wrote an implementation of this in case you're interested.

    http://cvs.sourceforge.net/viewcvs.py/twiff/twiff/twiff-core/src/java/net/trajano/twiff/web/RedirectServlet.java?rev=1.3&view=markup
  8. Use meta-refresh[ Go to top ]

    Rather than having a JSP left open, you can use HTTP meta-refresh to reload the page that checks if the procedure is done.

    If it detects that it is done, it will send a redirect to another URL that would display the data.

    This would save you some resources since you release the connection immediately after the checking if the data is available and the servlet can be reused for a different request.

    This only works with browser based solutions though.

    I am going to put this into my framework as well once I figure out how to get hibernate working.
  9. Thread safety[ Go to top ]

    The JSP page keep polling the thread to determine if the response has received.

    How are you holding a reference to your Runnable object? If you are holding it as a member variable, your solution will not be threadsafe, unless you use the isThreadSafe page directive. In that case, it becomes a singlethreaded servlet, which scales poorly.

    The only solution I can think of is to store a reference to the Runnable, or an indicator of the Runnable's progress, in the session context.
  10. Thread safety[ Go to top ]

    <How are you holding a reference to your Runnable object? If you are holding it as a member variable, your solution will not be threadsafe, unless you use the isThreadSafe page directive. In that case, it becomes a singlethreaded servlet, which scales poorly.

    The only solution I can think of is to store a reference to the Runnable, or an indicator of the Runnable's progress, in the session context.>>

    Adrian,

    I left out those details from my initial post. I basically have the Runnable object stored in the HttpSession.

    Tony.
  11. Thread safety[ Go to top ]

    <
    response.setHeader("Refresh", "5; URL=" );

    5 is the number of seconds
    Blank URL reloads current page. >>

    Thanks, this is a good piece of information.