File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Wait Thread ?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Wait Thread ??" Watch "Wait Thread ??" New topic
Author

Wait Thread ??

Malhar Barai
Author
Ranch Hand

Joined: Aug 17, 2001
Posts: 399
Hi all,
I have a servlet which loads some data to the database from a text file & even executes some other queries on the loaded data.
But as the data as increased, the connection to the server expires, how do I go around this problem, I thought of running some thread during the process which say "Your DATA is being transferred", is this the right way ??
Hope I am clear.
TIA
MB
PS. Welcome AUTHORS !!


Malhar Barai
SOA & Java Book
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

Do you want to display some temporary page?
[ January 28, 2004: Message edited by: Pradeep Bhat ]

Groovy
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
The usual approach to this is to return a "please wait" page immediately, while starting the processing as a background thread. Typically this "please wait" page will use a meta refresh tag to wait for a specified time, then attempt fetch a "results" page.
Does that make sense, or do you need more detail?


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Jayson Falkner
Author
Ranch Hand

Joined: May 07, 2001
Posts: 57
As mentioned above, the common way to sovle this problem is with a 'wait' page . Kevin and I provide an explicit example of this in the book, e.g.
---- snip -----
Auto-Refresh/Wait Pages
Another response header technique that is uncommon but helpful is to send a wait page or a page that will auto-refresh to a new page after a given period of time. This tactic is helpful in any case where a response might take an uncontrollable time to generate, or for cases where you want to ensure a brief pause in a response. The entire mechanism revolves around setting the Refresh response header(25). The header can be set using the following:

Where time is replaced with the amount of seconds, the page should wait, and url is replaced with the URL that the page should eventually load. For instance, if it was desired to load http://127.0.0.1/foo.html after 10 seconds of waiting, the header would be set as so:

Auto-refreshing pages are helpful because they allow for a normal pull model, waiting for a client s request, to push content. A good practical use case
----- snip ----
And there is a reference to a footnote or two that point to more information about the Refresh header and how it is supported in HTTP 1.0/1.1 and amongst the common web browsers.


Jayson Falkner<br />jayson@jspinsider.com<br />Author of <a href="http://www.jspbook.com" target="_blank" rel="nofollow">Servlets and JavaServer Pages; the J2EE Web Tier</a>
michael yue
Ranch Hand

Joined: Nov 20, 2003
Posts: 204
I have a problem with this refresh code. I put the refresh code line in a servlet and it only execute after the redirect line code which exist in my code. I dont know where to place the code. In my servlet there is a loop that takes quite some time to execute. How should I place the code?
Ko Ko Naing
Ranch Hand

Joined: Jun 08, 2002
Posts: 3178
Originally posted by rollin park:
I have a problem with this refresh code. I put the refresh code line in a servlet and it only execute after the redirect line code which exist in my code. I dont know where to place the code. In my servlet there is a loop that takes quite some time to execute. How should I place the code?

Try to put it at the beginning of ur servlet's method, even before the loop so that the header has been set at the very beginning... Hope it helps...


Co-author of SCMAD Exam Guide, Author of JMADPlus
SCJP1.2, CCNA, SCWCD1.4, SCBCD1.3, SCMAD1.0, SCJA1.0, SCJP6.0
michael yue
Ranch Hand

Joined: Nov 20, 2003
Posts: 204
Originally posted by Ko Ko Naing:

Try to put it at the beginning of ur servlet's method, even before the loop so that the header has been set at the very beginning... Hope it helps...


hi again
The wait page still won't display after i put it at top. I try to put in thread but to no avail. It keeps displaying the input page until it redirect to new page.Here is my code
Thread thread = new Thread();
thread.start();
//Include the Wait Page which should be displayed before the transaction starts
res.setHeader("Refresh", "1; URL=https://"+host+"/webjos/CVN/wait.html");
//execute the method that takes time example: insert 10000 records (in a for loop)
thread.stop();
if success
redirect to new page
END
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Wait Thread ??