You can also use the Singleton pattern, so no matter what happens,
you'll only have a single instance of your object.

- Behi

On 8/5/05, Jon Wingfield <[EMAIL PROTECTED]> wrote:
> Use a ServletContextListener, they were added to the Servlet 2.3 spec
> for this very purpose.
> You set up your object in the contextInitialized(...) method of your
> implementation and tear it down in contextDestroyed(...). For it to be
> used you need to add it to your web.xml.
> 
> The container is free to init and destroy servlets as it sees fit after
> complying with load-on-startup directives. That's why use of
> load-on-startup for initialization of application scope objects is prone
> to error and unforeseen circumstances.
> 
> my $0.02 and HTH,
> 
> Jon
> 
> Nicolas Schwartz wrote:
> > Hi all,
> >
> > I need an object to be instanciated on the startup of my tomcat.
> > So I did a servlet the creates an instance of it and put my servlet in
> > the web.xml of a webapp with the loadOnStartup parameter.
> > The constructor of my object is called twice so there must be 2
> > instances of it ... which is a problem.
> > (when I call the url of the servlet that creates the instance, only one
> > is created)
> >
> >
> > Could someone explain me why the constructor is called twice (why do I
> > have 2 instances ?)
> > and/or could someone give me another solution to have one and only one
> > instance of the object created on the tomcat startup ?
> >
> > Thanks,
> >
> > Nicolas
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 


-- 

Behrang Saeedzadeh
http://www.jroller.com/page/behrangsa

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to