tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Elliot Schwartz ...@mit.edu>
Subject Re: how to run a class on startup of tomcat ??
Date Wed, 15 Nov 2000 23:34:44 GMT
Sudheshna Methuku <MethukuS@iictechnologies.com> writes:

> We used a servlet with init() and destroy() methods to start the services we
> wanted to run at the tomcat startup and stop when tomcat is stopped. But we
> found that the servlet's init() is getting called 5 times and destroy is not
> at all being called. 

I'm new to Tomcat but I can make some wild guesses here, since I ran into
similar issues with JServ.

The reason init() is getting called 5 times is probably because 5 instances of
the servlet have been created, so that multiple requests for that servlet
can be handled simultaneously. What we did to deal with this was just have the
servlet call a method in a singleton class, which only performed the
initialization the first time it was called. I'm not sure if that's the
best way to do this. You may also be able to get only a single instance
of the servlet created by modifying some Tomcat parameters or perhaps even
by not using the single-thread model.

What we currently do is a little different: we write our own main() which 
has initialization code, and then start Tomcat, as opposed to trying to
put initialization code that's not really related to any particular servlet
into a servlet.

As for the destroy problem, I'm not sure. Perhaps Tomcat doesn't yet
destroy the servlets when they are no longer needed.

elliot


> 
> The xml tag we used in web.xml is 
> 
> <servlet>
>         <servlet-name>initializerServlet</servlet-name>
>         <servlet-class>InitializerServlet</servlet-class>
>         <load-on-startup>1</load-on-startup>
> </servlet>
> 
> Any clues what could be the problem.
> 
> Thanks,
> Sudheshna.M.
> 
> 
> -----Original Message-----
> From:
> tomcat-user-return-14832-MethukuS=iictechnologies.com@jakarta.apache.org
> [mailto:tomcat-user-return-14832-MethukuS=iictechnologies.com@jakarta.ap
> ache.org]On Behalf Of Christian Mack
> Sent: Monday, November 06, 2000 5:22 PM
> To: 'tomcat-user@jakarta.apache.org'
> Subject: RE: how to run a class on startup of tomcat ??
> 
> 
> Hi Sudheshna
> 
> That's easy.
> Just use a servlet which gets startet on tomcats startup.
> In it's init() just start your Runnable.
> The doXXX() methods are empty, as this servlet will never be called.
> 
> Tschau
> Christian
> 
> > -----Original Message-----
> > From: Sudheshna Methuku [mailto:MethukuS@iictechnologies.com]
> > Sent: Monday, November 06, 2000 7:25 AM
> > To: tomcat-user@jakarta.apache.org
> > Cc: Subhashini Chirunomula; Marthi Nalini
> > Subject: how to run a class on startup of tomcat ??
> > 
> > 
> > Hi All,
> > 
> > We have a startup class which needs to be run when tomcat is 
> > started. Could
> > anyone pl. tell us how it is possible. The startup class is 
> > not a servlet,
> > it implements runnable and it in turn starts some more threads. 
> > 
> > Thanks,
> > Sudheshna.M.
> > 
> 

Mime
View raw message