If it's just a simple task that has to be done
at a regular interval, you can use client pull,
as given in Jason Hunter's book on servlets -
sample code :
public class ClientPullExample extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/plain");
PrintWriter out = response.getWriter();
response.setHeader("Refresh", "5");
// out.println(new Date().toString());
// put your code here
}
}
This sends a "Refresh at 5 seconds" command to
the browser via the HTTP header - most browsers
support this, acc. to the book.
HTH
Vasudev
> -----Original Message-----
> From: Jay Macarty [SMTP:[EMAIL PROTECTED]]
> Sent: Monday, August 23, 1999 4:05 AM
> To: [EMAIL PROTECTED]
> Subject: Re: Using servlets for periodic background processes
>
> Ben,
> I have just completed a project which allows users to query certain stock
> quote information. Rather than perform the query every time I get a
> request,
> I start a background thread in the init() method of the servlet which
> queries the Wall Street server every 15 minutes and builds a set of
> stockQuote objects. In the doGet() method of the servlet a simple
> StockThread.getQuotes() method is called to do a synchronized read of the
> quote Hashtable. It has worked quite well and makes for a very low
> resource
> load application.
>
> ----- Original Message -----
> From: Ben Coppin <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Friday, August 20, 1999 5:03 AM
> Subject: Using servlets for periodic background processes
>
>
> > Has anyone investigated the use of servlets to carry out periodic tasks?
> I
> > have a servlet through which users can select topics on which they want
> to
> > be emailed regularly. I was thinking that it might be neat if instead of
> > using cron to do this, I had a separate thread in the servlet, or
> perhaps
> a
> > separate servlet periodically wake up and send out emails and then go
> back
> > to sleep.
> >
> > Does this sound like a daft idea, or has someone out there already done
> > something like this?
> >
> > Thanks,
> >
> > Ben
> >
> >
> __________________________________________________________________________
> _
> > 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
___________________________________________________________________________
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