• 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

background processing

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Does anybody know a way to call a JSP which displays information (eg please wait...) and at the same time automatically initiates a server program for background processing. When the server process has completed then control passes to the next web page.

Thanks
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
may be this will help you.

i have encountered the same thing in one more thread. i couldn't found right now, you can search the jsp forum for that.
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
k, you do it this way,


Let us assume we have page1 , page2 and you are moving from page1 to page2 and in the mean while as this is a time taking process you want to show a please wait page.

Let us assume that the page with please wait is called "interim". now when you click on submit dont call the url for page2 but instead call the url for interim passing the same data that you would pass to page2 and let the interim page on page load call the page2... this will achieve your purpose.
 
rex johnson
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Murthy,

This seems fine and also simple.

One point though when I tried this out I found that the animated gif on the 'interim' page became a static gif. Is this a consequence of calling the server program immediately and is there any way around this.

Rex
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HTTP is strictly request/response, so it's not a good idea to try to play games of that sort. A long-running process under a servlet will simply not return until the process is done and a thread spawned but not tracked will get lost.

What you can do is create a background thread and store it in your session, then set up the page to use the refresh meta-tag to poll the server periodically to see if the thread is finished.

This is a moderately complex task (usually takes me a day or so of coding to get going), so rather than explain in detail (and forget critical things), I'd recommend you search through similar messages in this forum and especially in the servlets forum.
 
Murthy Cherukumilli
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
there is no thread being spawn here it is just a simple forward of request but that we introduced a interim page thats all we are doing..

and as far as the animation being lost i dont think this has got to do what youare doing... becasue alll you are doing is onload which means your page is already loaded...so dont think that cold be an isssue.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Browsers will not play GIF animations while they are loading the next page.

Tim's approach is your best bet for a robust way to deal with long-running processes.

A "Poor Man's" version of this which I have seen used (but which is not as robust), is to have your request submitted to a page which includes your "please wait" message (or animation or whatever) and whose onLoad handler submits the "real" (long running) request to a hidden iframe on the page. When the sub-request compeletes, its response contains Javascript to cause the parent page to reload as appropriate.

The main problem with this appraoch is that if the user refreshes the parent page, all hell can break loose unless you have added guard code to prevent re-submission of the sub-request.

Again, I recommend following Tim's advice.
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i also recommend Tim's advice, but i would use a MDB instead of a thread. Let the bean write some kind of flag that the refreshing page can consult until the work is done, then it can redirect to the next page.
[ October 14, 2004: Message edited by: Pedro Gongora ]
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If he's not already using EJB's I don't think adopting them just to do this is necessary.
 
Murthy Cherukumilli
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
nice point raised my bear bartender... hmm.. i miissed it totally ... but can you please explain ... in tims approach why do we need to keep the thread in the session... what is the necessity.?
 
rex johnson
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the responses and I understand the potential problems with the original solution.

In fact the scenario that I am trying to cater for involves just checking whether or not a database background task initiated by another event has completed.

In this case I think that I am safe to use the refresh meta tag on my 'please wait' page to request the check from a servlet and respond accordingly
reply
    Bookmark Topic Watch Topic
  • New Topic