Return-Path: Delivered-To: apmail-jakarta-tomcat-user-archive@jakarta.apache.org Received: (qmail 83930 invoked by uid 500); 14 Jun 2001 21:18:32 -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 83889 invoked from network); 14 Jun 2001 21:18:28 -0000 Received: from unknown (HELO cybershop.ca) (207.236.177.2) by h31.sny.collab.net with SMTP; 14 Jun 2001 21:18:28 -0000 Received: from cybershop.ca [207.236.177.12] by cybershop.ca [207.236.177.2] with SMTP (MDaemon.v2.8.5.0.R) for ; Thu, 14 Jun 2001 17:06:19 -0400 Message-ID: <3B29296A.964CEC8@cybershop.ca> Date: Thu, 14 Jun 2001 17:15:22 -0400 From: Bo Xu X-Mailer: Mozilla 4.7 [en] (WinNT; I) X-Accept-Language: en MIME-Version: 1.0 To: tomcat-user@jakarta.apache.org Subject: Re: How can I make tomcat to instantiate a class References: <01061318575500.02823@debashis> <016501c0f4e5$55b3aaa0$87c6fea9@computer> <01061411294400.01819@debashis> <00ad01c0f50b$231073a0$87c6fea9@computer> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-MDaemon-Deliver-To: tomcat-user@jakarta.apache.org X-Return-Path: bo@cybershop.ca X-Spam-Rating: h31.sny.collab.net 1.6.2 0/1000/N > ...But actually my problem was to instantiate a class when > tomcat boots up...so 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 connection. 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 closed. ... * and I think perhaps there is another way: - make a "startupServlet", and in its "servlet-declaration" in WEB-INF/web.xml, set the following: 1 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{ super.init(config); ... startupUtility.makeInstance(); ... } - now after a while(instantiating time), a instance of startupUtility is available (for example, a DBConnectionpool) Bo June 14, 2001