I think Tim makes some very valid points. In my application I configured the
servlet engine to "preload" the servlet containing the thread. Also, I coded
a destroy() method for the servlet to stop the thread and set the thread
object to null.
----- Original Message -----
From: Tim Panton <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, August 21, 1999 4:52 AM
Subject: Re: Using servlets for periodic background processes
> > Nic Ferrier wrote:
> > >
> > > Personally I think it's a bad idea.
> > >
> >
> > Hi,
> >
> > The idea sounds good to me. :) This servlet-cron service would simply
> > run in its own thread, and wakes up periodically. This could be
> > configured depending on the site's design. Maybe every 30 seconds
> > would be a good start. It would check if there's any tasks at that
> > point in time to be done, and when through go back to sleep
>
> I don't think a generic cron replacement servlet is a good idea,
> Cron has lots of nice properties that are hard to do in the servlet
> environment like :
> Persistence across reboots/crashes
> correct actions over DST changes (allegedly)
> reliable one-shot actions
> run as less (or more) privileged user
>
> If however you have a bit of servlet (or webapp) related periodic
> activity,
> then it is fine to code up a thread to be spun off from a servlet,
> but be very aware of the servlet lifecycle as it is implemented in your
> web server/engine.
>
> Here are a couple of things that might trip you up:
> 1) In some engines servlets are not loaded until the first use,
> so your cron-servlet may never be loaded unless you take special steps.
> 2) Some engines will destroy a servlet that's been idle for a long
> time, and then subsequently start a new instance. Your background thread
> however may still have a reference to the old servlet, and update the
> state
> of the 'destroyed' one.
> 3) Some engines have multiple VM's running, be sure that the cron
> servlet is in the one you want, i.e. the JVM serving https: servlets may
> not
> be the same as the one serving http: servlets.
>
> None of these issue are insurmountable, but they sure can slow you down,
> as I've discovered.
>
> T.
>
>
___________________________________________________________________________
> 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