Please browse the categories below to previous answers to questions like yours. If you do not find the answer for your particular situation, ask for help on the appropriate mailing list.
(Answer) (Category) Java Apache Project : (Category) Apache JServ 1.0 : (Category) Programming and Misc. Tidbits :
Ideas for dealing with long running computations in servlets...
----------
From: "Craig R. McClanahan" cmcclanahan@mytownnet.com
To: Java Apache Users java-apache-users@list.working-dogs.com
Subject: Re: Detecting canceled/broken requests?
Date: Sat, Jun 12, 1999, 12:21 PM


Matt Feiszli wrote:

> First, thanks for the info.  But I think I framed the question poorly.
> This will solve some of my problems, but if I have a long-running
> computation that produces no output until it's done (e.g. long database
> query), the query will still run to completion before the servlet can
> find out.  I'd like to get interrupted or notified somehow, analogous to
> getting a SIGPIPE if I were in a normal UNIX environment.  I suppose I
> could rewrite the servlet to send a little bit of whitespace every so
> often while it's waiting for the query results, but this seems ugly.  It
> would be nice if there were a cleaner way.  There's nothing in the
> servlet API that seems to address this.
>
> -Matt
>

Another strategy I've heard people say they used in this situation is to
start the long-running computation in a background thread, which will store
its final results into a user's HttpSession.  Then, your servlet can return
immediately after the computation is started, with a "computation in
progress" message.  Each time the user invoked the servlet again, it would
see that the computation was still running (and say so again), or that it
has been completed (and display the results).

You could get even fancier and do a "% completed" indicator for the progress
that the computation is making, or give the user an option to interrupt the
ongiong computation if they decide that they don't want to wait for the
results to be completed.

Craig McClanahan
[Append to This Answer]
sajidaATadvcommDOTnet, jonATworking-dogsDOTcom
Previous: (Answer) Path translation issues...
Next: (Answer) Why do I get a ClassNotFoundException on my JDBC driver?
This document is: http://java.apache.org/faq/?file=212
[Search] [Appearance] [Show Expert Edit Commands]
This is a Faq-O-Matic 2.709.
Please browse the categories below to previous answers to questions like yours. If you do not find the answer for your particular situation, ask for help on the appropriate mailing list.