tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bo Xu>
Subject Re: How can I make tomcat to instantiate a class
Date Thu, 14 Jun 2001 21:15:22 GMT
> ...But actually my problem was to instantiate a class when
> tomcat boots that i can use that object across sessions.Can u
> suggest something towarsd this.
> [...]

Hi :-)  I find the following is from servlet-2_3-pfd2-spec.pdf(for
Servlet containers which supports Servlet spec2.3):

SRV.10.2.2 An Example of Listener Use
To illustrate a use of the event scheme, consider a simple web application
containing a number of servlets that make use of a database. The developer
has provided a serv-let context listener class for management of the database
1. When the application starts up, the listener class is notified. The
application logs on to the database, and stores the connection in the
servlet context.

2. Servlets in the application access the connection as needed during
activity in the web application.

3. When the web server is shut down, or the application is removed from
the web server, the listener class is notified and the database connection is

* and I think perhaps there is another way:
   - make a "startupServlet", and in its "servlet-declaration" in
     WEB-INF/web.xml, set the following:
      now/so when TC is started, the "init" method of this "startupServlet"
      will be invoked by container
   - in the "init" method in this "startupServlet", a SingleTon pattern
     "startupUtility" is instantiated: for example, by invoking a public static
     "Factory method":
      public void init(ServletConfig config) throws ServletException{

   - now after a while(instantiating time),  a instance of  startupUtility is
     (for example, a DBConnectionpool)

June 14, 2001

View raw message