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.
-
Technical dilemma! Any suggestions (10 messages)
- Posted by: Tony Blair
- Posted on: March 03 2005 12:43 EST
Threaded Messages (10)
- Technical dilemma! Any suggestions by Amit Kumar on March 03 2005 17:23 EST
- Technical dilemma! Any suggestions by Tony Blair on March 04 2005 07:13 EST
-
Technical dilemma! Any suggestions by Tony Blair on March 04 2005 07:15 EST
-
coincidence by adrian osullivan on March 04 2005 08:54 EST
- coincidence by Archimedes Trajano on March 04 2005 12:19 EST
- Sample implementation by Archimedes Trajano on March 05 2005 10:51 EST
-
coincidence by adrian osullivan on March 04 2005 08:54 EST
-
Technical dilemma! Any suggestions by Tony Blair on March 04 2005 07:15 EST
- Technical dilemma! Any suggestions by Tony Blair on March 04 2005 07:13 EST
- Use meta-refresh by Archimedes Trajano on March 04 2005 03:17 EST
- Thread safety by adrian osullivan on March 04 2005 09:56 EST
- Thread safety by Tony Blair on March 04 2005 14:55 EST
- Thread safety by Tony Blair on March 04 2005 14:58 EST
-
Technical dilemma! Any suggestions[ Go to top ]
- Posted by: Amit Kumar
- Posted on: March 03 2005 17:23 EST
- in response to Tony Blair
Your way sounds perfect to me. Are you facing any problem also? -
Technical dilemma! Any suggestions[ Go to top ]
- Posted by: Tony Blair
- Posted on: March 04 2005 07:13 EST
- in response to Amit Kumar
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. -
Technical dilemma! Any suggestions[ Go to top ]
- Posted by: Tony Blair
- Posted on: March 04 2005 07:15 EST
- in response to Tony Blair
don't know much about HTTP - meta refresh...guess I need to read up on that. Have any sample code?
Thanks. -
coincidence[ Go to top ]
- Posted by: adrian osullivan
- Posted on: March 04 2005 08:54 EST
- in response to Tony Blair
Just implementing a very similar thing myself!
response.setHeader("Refresh", "5; URL=" );
5 is the number of seconds
Blank URL reloads current page. -
coincidence[ Go to top ]
- Posted by: Archimedes Trajano
- Posted on: March 04 2005 12:19 EST
- in response to adrian osullivan
I didn't know about that blank URL trick. Does it work in Opera, Firefox and IE? Is it documented in w3c? -
Sample implementation[ Go to top ]
- Posted by: Archimedes Trajano
- Posted on: March 05 2005 22:51 EST
- in response to Tony Blair
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 -
Use meta-refresh[ Go to top ]
- Posted by: Archimedes Trajano
- Posted on: March 04 2005 03:17 EST
- in response to Tony Blair
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. -
Thread safety[ Go to top ]
- Posted by: adrian osullivan
- Posted on: March 04 2005 09:56 EST
- in response to Tony Blair
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. -
Thread safety[ Go to top ]
- Posted by: Tony Blair
- Posted on: March 04 2005 14:55 EST
- in response to adrian osullivan
<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. -
Thread safety[ Go to top ]
- Posted by: Tony Blair
- Posted on: March 04 2005 14:58 EST
- in response to adrian osullivan
<
response.setHeader("Refresh", "5; URL=" );
5 is the number of seconds
Blank URL reloads current page. >>
Thanks, this is a good piece of information.