tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <craig...@apache.org>
Subject Re: on startup
Date Tue, 11 Sep 2001 15:23:29 GMT


On Tue, 11 Sep 2001, simon wrote:

> Date: Tue, 11 Sep 2001 13:53:42 +0900
> From: simon <simon@lexues.co.jp>
> Reply-To: tomcat-user@jakarta.apache.org
> To: tomcat-user@jakarta.apache.org
> Subject: Re: on startup
>
>
> ----- Original Message -----
> From: "Kamran Mazandrani" <kamranmz@netropolis.net>
> To: <tomcat-user@jakarta.apache.org>
> 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" <craigmcc@apache.org>
> > Sender: <craigmcc@localhost>
> > To: <tomcat-user@jakarta.apache.org>
> > 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



Mime
View raw message