Here's how I would handle it in meta-code.
Create a class that extends Thread (or implements Runnable) who's job is to
perform the query in its run method. Instantiate the class and give it the
query to perform. One of its other features would be to set a flag when it
was done.
In the main body of the servlet, when a request is received, gather enough
information to build the query, construct one of your Query objects and
start it running, then enter a small loop, like this.
for i = 1 to 10
if the query is done
exit the loop and return the results page
otherwise
sleep for 1 second
if the loop ends without the query reporting done (after 10 seconds),
redirect the user to a "Please Wait" page with the META-EQUIV tag that will
time out in another 30 seconds. When that request is received, check to see
if the thread (which you will have placed in the Session) has finished
processing, if not, enter your loop again.
(*Chris*)
----- Original Message -----
From: David O'Callaghan <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, April 29, 1999 6:13 PM
Subject: Server timeout - (Again)
> I've been through the archives and I thought the "please wait page" thread
was
> the solution to my problem. However after spending some time with the
examples
> I still can't get my servlet to work.
> All I want to do is query a DB, get some info, process it and return some
> data to the user. This will work fine if the user is very specific in
their
> requests but if they don't narrow down the search then the serverlet will
> timeout before the results are returned and processed.
> If there is a "simple" and straight forward way to solve this problem I
would
> really love to hear it. I've been struggling with this for over a week and
I'm
> out of ideas. I thought about putting all the processing in a thread and
> joining up with the thread when it was ready but I feel this is the
completly
> wrong approach for servlets.
> I've included the sample I'm working with below. Its a slightly modified
piece
> of code from the example posted previously on this list. I have set the
loop to
> be really high to show that the server will timeout before the results are
> returned.
>
> ########## timeout.java ##################
> import java.io.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
>
> public class timeout extends HttpServlet {
> public void init(ServletConfig conf) throws ServletException {
> }
>
> public void doGet(HttpServletRequest req, HttpServletResponse res)
> throws ServletException, IOException {
>
> res.setContentType( "text/html" );
> HttpSession session = req.getSession( true );
> PrintWriter out = res.getWriter();
>
> if ( session.getValue( "waitPage" ) == null ) {
> session.putValue( "waitPage", Boolean.TRUE );
> out.println( "<html><head>" );
> out.println( "<title>Please Wait...</title>" );
> out.println( "<meta http-equiv=\"Refresh\" content=\"0\">" );
> out.println( "</head><body>" ); out.println( "<br><br><br>" );
> out.println( "<center><h1>Testing if server will timeout<br>" );
> out.println( "Please wait.</h1></center>" );
> out.close();
> }
> else {
> session.removeValue( "waitPage" );
> out.println( "<html><head><title>Timeout test</title></head>" );
> out.println( "<body>" ); out.println( "<h1>Finished</h1>" );
> for ( int i = 1000; i > 0; i-- ) {
> out.println( i + " " );
> try { Thread.sleep( 10000 ); } // Decrease value to stop timeout
> catch ( InterruptedException e ) {} }
> out.println( "<h1>Server did not timeout</h1>" );
> out.println( "</body></html>" ); out.close();
> }
> }
> }
>
>
___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html