• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Wanted: Design pattern for handling time consuming HTTP requests

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!
In my application the user will have to wait for the server to execute requests that sometimes will take more than 10 secs to perform. During this time, I would like the users to be able to continue with certain non-sensitive operations. When to request is done, the web application should somehow notify the user and present the result to her/him.
Has anybody a good implementation of this feature?
PS. We use WebSphere 3.5 and IBM HTTP Server.
//Johan
 
Author
Posts: 245
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
first store a result object - an object that will hold the result of the operation - in session. This will act as a flagto the status.
spin off a thread that takes care of the time consuming operation and pass that thread the user's session (and therefore the result object0 to store the result in.
Now if the operation is literaly only 10secs, then I personally dont think that there is any point in allowing the user to continue using non-sensitive parts of the web app - what can someone do in 10s? just show a hold page, with a meta refresh tag of 10secs (and/or a javascript function that does the same plus a link in case neither works - a very unlikely situation) and put a gif of a moving clock or some such thing to show elapsed time. FOr an example see virgintrains.co.uk (search for a journey - for example hull to manchester)
if it does make sense to carry on the processing in parallel for some reason, a possible solution is to provide a template in each page that displays the state of any outstanding work belonging to the user by checking the session for the result object and checking its state. If no result object exists then nothing is shown, otherwise its state is shown together with a link to a page that can extract the result object from session and display the result:

[ December 05, 2002: Message edited by: chanoch wiggers ]
 
Author
Posts: 399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Originally posted by chanoch wiggers:
first store a result object - an object that will hold the result of the operation - in session. This will act as a flagto the status.
spin off a thread that takes care of the time consuming operation and pass that thread the user's session (and therefore the result object0 to store the result in.
Now if the operation is literaly only 10secs, then I personally dont think that there is any point in allowing the user to continue using non-sensitive parts of the web app - what can someone do in 10s? just show a hold page, with a meta refresh tag of 10secs (and/or a javascript function that does the same plus a link in case neither works - a very unlikely situation) and put a gif of a moving clock or some such thing to show elapsed time. FOr an example see virgintrains.co.uk (search for a journey - for example hull to manchester)



if it does make sense to carry on the processing in parallel for some reason, a possible solution is to provide a template in each page that displays the state of any outstanding work belonging to the user by checking the session for the result object and checking its state. If no result object exists then nothing is shown, otherwise its state is shown together with a link to a page that can extract the result object from session and display the result:

[ December 05, 2002: Message edited by: chanoch wiggers ]


hello dear
can you explain with bit more details, my operation last for about 20-25 secs & then shows the result, sometimes even more than this due to ISP's speed problem
tia
MB
 
Johan Apelgren
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank's!
This sounds like a well designed solution. I have two comments:
1) You wrote:

"spin off a thread that takes care of the time consuming operation and pass that thread the user's session (and therefore the result object0 to store the result in."
Is this a safe operation to perform within a J2EE application server and/or a web server? I thought threading was one of the things the appserver ought to handle automatically?
2) You also wrote:
"a possible solution is to provide a template in each page that displays the state of any outstanding work belonging to the user by checking the session for the result object and checking its state. If no result object exists then nothing is shown, otherwise its state is shown together with a link to a page that can extract the result object from session and display the result"
Our application is a "fat" web client. That is, it is implemented with payloads of DIV tags and Javascripting, and only access the web server when it's time for bulk operations (+10 secs) that I mentioned in my previous posting.
I mention this because I think this template solution would work just fine if the application make a HTTP request to the web server every time the user "clicks" in the GUI. But for us the "template" would have to check the session in a hidden form or something. Could this be done?
Are there better alternatives, since I have got the impression that hidden forms are "dirty" design?
 
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you have MQSeries available to you, then you can avoid spinning off a thread by:
(1) Making your "handler" that executes the long business process run as a JMS MessageListener.
(2) Phrase the "Request" to the handler as putting a message on a queue
(3) Have the Servlet that is polled for the result by the client check a reply queue to see if a reply has been returned.
This is actually easiest in something like WebSphere 5.0, which has JMS built in, but if you have MQ Series, it's easy (and fully J2EE compatible) to build. This way of accomplishing long-running processes is actually one of IBM's best practices for WAS 5.0.
Kyle
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic