On 4/27/07, Srinivas V. <[EMAIL PROTECTED]> wrote:
Hello all

I have a question about defining data-sources in tomcat. I have a webapp in
which my servlets need to talk to a DB. This is my current setup:

1) I define data-sources (c3p0 connection pools) using the Resource tag in
my META-INF/context.xml.
2) The web.xml has references these data-sources via resource-env-ref tags
3) In my servlet init(), I lookup the data-source. Each lookup essentially
instantiates an instance of the data-source. So a connection pool gets
instantiated in each servlet's init.

Now it doesn't make sense to create a new connection pool in each servlet.
So I'd like to create a single connection pool that will be used by all
servlets. I've been looking thru the tomcat docs, to see where I could
create this central resource for my webapp. The only option I've seen so far
is to create my own life-cycle listener for my webapp. That way I can create
a connection pool on start-up.

I've seen people using ServletContextListener instead of
LifeCycleListener. That way you don't have to write your own listener.

contextInitialized() method is invoked when Tomcat starts or re-loads.

Reference: 
http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletContextListener.html

You may already know that the listener must be registered in web.xml
under a <listener> tag.

I was wondering if there was a better way to
do this ?

       Thanks

      Srinivas


-Regards
Rashmi

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to