Return-Path: Delivered-To: apmail-jakarta-tomcat-user-archive@jakarta.apache.org Received: (qmail 89734 invoked by uid 500); 11 Sep 2001 15:27:39 -0000 Mailing-List: contact tomcat-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk Reply-To: tomcat-user@jakarta.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list tomcat-user@jakarta.apache.org Received: (qmail 89723 invoked from network); 11 Sep 2001 15:27:38 -0000 Date: Tue, 11 Sep 2001 08:23:29 -0700 (PDT) From: "Craig R. McClanahan" Sender: To: Subject: Re: on startup In-Reply-To: <002101c13a7d$bed0ea10$2500a8c0@powerstation.ne.jp> Message-ID: <20010911081750.E36687-100000@localhost> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Spam-Rating: localhost 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N On Tue, 11 Sep 2001, simon wrote: > Date: Tue, 11 Sep 2001 13:53:42 +0900 > From: simon > Reply-To: tomcat-user@jakarta.apache.org > To: tomcat-user@jakarta.apache.org > Subject: Re: on startup > > > ----- Original Message ----- > From: "Kamran Mazandrani" > To: > 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" > > Sender: > > To: > > 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