On Tue, 11 Sep 2001, simon wrote:
> Date: Tue, 11 Sep 2001 13:53:42 +0900
> From: simon <[EMAIL PROTECTED]>
> Reply-To: [EMAIL PROTECTED]
> To: [EMAIL PROTECTED]
> Subject: Re: on startup
>
>
> ----- Original Message -----
> From: "Kamran Mazandrani" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Tuesday, September 11, 2001 1:54 PM
> Subject: Re: on startup
>
>
> > Date: Fri, 7 Sep 2001 11:11:10 -0700 (PDT)
> > From: "Craig R. McClanahan" <[EMAIL PROTECTED]>
> > Sender: <craigmcc@localhost>
> > To: <[EMAIL PROTECTED]>
> > Subject: RE: How can I have a class run on start-up?
> >
> > For a portable solution to the "run my class at startup" problem, Servlet
> > 2.3 (and therefore Tomcat 4.0) supports a new API called
> > javax.servlet.ServletContextListener. If you register such a listener in
> > your web.xml file, the container will call the contextInitialized() method
> > when the web application starts up, and contextDestroyed() when the web
> > application is shut down.
> > This is safer than the typical approach (use the init() method of a
> > load-on-startup servlet), because the servlet specification does *not*
> > guarantee to keep any particular servlet instance in memory for the life
> > of the application (although Tomcat actually does so).
> > Craig
>
> Is this true?
See the Servlet Specification, either 2.2 or 2.3, the chapter on Servlets.
In 2.3, it's in Section 2.3.4, the very first sentence. You can download
the spec from:
http://java.sun.com/products/servlet/download.html
I'm continually surprised by how many developers don't know about the
servlet specs. The rules defined here are *just as important* as the
rules stated in the Javadocs (in fact, the 2.3 spec *includes* the
Javadocs :-) at defining what a servlet container does and doesn't do for
you.
Long time readers of TOMCAT-USER will note that this has been my favorite
URL reference lately -- there is a message here :-) :-)
> Under what circumstances would a servlet be removed from memory?
>
Remember that containers often run for a very long time, against a request
processing load that varies dynamically. If the container detects that it
is close to running out of memory, it makes a lot of sense to consider
deactivating servlet instances that haven't been called for a while, in
order to reuse the memory space occupied by those servlets. They will be
restarted automatically if they are requested again, so there's no
difference to the programming model -- except that you need to be aware
that servlet instances are not permanent.
> simon
>
>
>
Craig