I suggest using a static block, as shown below. No matter how many servet
instances are created, the static block will only execute once.
=============
public class MyServlet
{
protected static DatabasePool dbPool=null;
static
{
try
{
dbPool=new DatabasePool();
}
catch (Throwable t)
{
(log error)
}
}
....
}
==============
--Zeba
At 06:34 PM 11/15/00 -0500, Elliot Schwartz wrote:
>Sudheshna Methuku <[EMAIL PROTECTED]> 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.
--
Zebadiah Kimmel
Chief Technology Officer
Zebware, Inc.
[EMAIL PROTECTED]
www.instantcanvas.com
www.zebware.com
212-780-1994 phone
646-638-3901 phone
646-638-3905 fax
30 West 21st St.
8th Floor
NY, NY 10010