tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kamran Mazandrani <kamra...@netropolis.net>
Subject Re: on startup
Date Tue, 11 Sep 2001 04:54:22 GMT

Mailing-List: contact tomcat-user-help@jakarta.apache.org; run by ezmlm
Reply-To: tomcat-user@jakarta.apache.org
list-help: <mailto:tomcat-user-help@jakarta.apache.org>
list-unsubscribe: <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
list-post: <mailto:tomcat-user@jakarta.apache.org>
Delivered-To: mailing list tomcat-user@jakarta.apache.org
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?
X-Spam-Rating: localhost 1.6.2 0/1000/N
X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N
X-RCPT-TO: <kamranmz@netropolis.net>

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

On Fri, 7 Sep 2001, Peter Romianowski wrote:
 > Date: Fri, 7 Sep 2001 19:35:32 +0200
 > From: Peter Romianowski <antarapero@gmx.de>
 > Reply-To: tomcat-user@jakarta.apache.org
 > To: tomcat-user@jakarta.apache.org
 > Subject: RE: How can I have a class run on start-up?
 >
 > you could implement a org.apache.catalina.LifecycleListener and attach 
it to
 > the context you are using like this:
 >
 > <Context path="/myapp" ...>
 > ...
 > <Listener className="com.mycompany.MyAppListener"/>
 > ...
 > </Context>
 >
 > look into the docs for details.
 > but this is a tomcat-specific thing (and thus not portable).
 >
 > anyway there's a second approach that comes in mind (but it is not as
 > "clean" as the first one)
 >
 > you simply could write a servlet where you put all code which should be
 > executed during webapp-initialization into the init-method.
 > in web.xml you configure the servlet to load on startup. it goes like this:
 >
 > <servlet>
 > <servlet-name>somename</servlet-name>
 > <servlet-class>someclass</servlet-class>
 > <load-on-startup>a value greater 0</load-on-startup>
 > </servlet>
 >
 > then the servlet will be called upon webapp-initialization.
 >
 > dont know if there's is a better (cleaner and portable) solution, but these
 > two do the job.
 >
 > greets,
 > pero
 >
 > -----Original Message-----
 > From: Jonathan Eric Miller [mailto:jemiller@uchicago.edu]
 > Sent: Friday, September 07, 2001 7:15 PM
 > To: tomcat-user@jakarta.apache.org
 > Subject: Re: How can I have a class run on start-up?
 >
 >
 > I don't know the answer to your question, but, I'm wondering if the
 > application actually has to run in Tomcat. It sounds like you might want to
 > just create a standalone application that listens on a port.
 >
 > Jon
 >
 > ----- Original Message -----
 > From: "Alex Colic" <alex.colic@pop-ware.com>
 > To: "Tomcat-User" <tomcat-user@jakarta.apache.org>
 > Sent: Friday, September 07, 2001 8:36 AM
 > Subject: How can I have a class run on start-up?
 >
 >
 > > Hi,
 > >
 > > hopefully someone can help me with this. I need some type of a class to
 > > start when the web server starts. This class is going to bind itself to a
 > > port and listen to commands from a VB app. Other classes in other web 
apps
 > > will register themselves with this class to receive these commands.
 > >
 > > My questions are:
 > >
 > > 1: how can you have a class start when the web server starts? This needs
 > to
 > > work with all web servers.
 > > 2: how can you have a class in a web app register itself with the class
 > > listening on the port?
 > >
 > > Any suggestions are appreciated.
 > >
 > > Regards
 > >
 > > Alex Colic
 > >
 >
 >




At 10:22 AM 9/11/2001 +0530, you wrote:
>hi all,
>I have a java class that needs to be loaded at the startup of the tomcat
>
>server. And I want it to persist as long as tomcat is alive. Is it
>possible ?
>If so where do i put the class ?
>Can i do it by changing something in any of the config files ?
>
>
>help please.
>
>regards
>anagha.
>
>--
>Where the mind is without fear and the head is held high;
>Where knowledge is free;
>Where the world has not been broken up into fragments by narrow domestic
>walls;
>Where words come out from the depths of truth;
>...............
>Where the mind is led by thee into ever-widening thought and action;
>Into that heaven of freedom,my Father,let my country awake.


Mime
View raw message