tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Johnny Kewl" <>
Subject Re: Dynamically adding a resource to a context
Date Wed, 01 Oct 2008 03:40:39 GMT

----- Original Message ----- 
From: "Scott Dunbar" <>
To: <>
Sent: Tuesday, September 30, 2008 10:22 PM
Subject: Dynamically adding a resource to a context

> Hi all,
> I'm honestly not positive that what I want to do is a good idea but the 
> basic concept is that I want to dynamically add a Resource (a JNDI JDBC 
> DataSource) to a Context.  The idea is that I will be dynamically creating 
> databases for new users and want to have a database connection pool for 
> each user.
> I've been able to simply hand modify 
> ${catalina.home}/conf/Catalina/localhost/contextname.xml and seen that I 
> can now access the new DataSource.  What I'm looking for is a programmatic 
> way to do the same thing, short of parsing and rewriting the XML myself. 
> I've dug though the MBean classes and am honestly a bit confused.
> Is there something that I'm missing?  This is Tomcat 6.0.18 under Linux 
> and/or Windows.
> Thanks for any help.

Scott, dont think so, I think the pools are created either as Tomcat starts 
or as the servlets starts...
I suppose you could write your own JNDI dB pool class as decribed here...

By definition, if you giving each user their own dB... a single connection, 
its going to be some kind of user pool, not a connection pool...
Unusual I must say... possibly a user table in a dB is a better way to go... 
but its your app.

... this is what you need to know...

The INIT function in a servlet runs once when it starts... and its quite 
easy and possible to use a dB pool without using JNDI...
ie many people use their own, or a third party dB pool and usually then dont 
use JNDI because it becomes a self contained war... especially in cases 
where there is an embedded dB...

In your case you would set up your user pool in INIT... use normal JDBC... 
and use it in the servlet.
Then run it against the logged in user.... or alternatively store 
connections as session cookies.... will then also need a listener...

It really depends on how hot your JDBC is ;) these pools are pretty smart 
things... and make suer you understand that a servlet is multi threaded...

Good Luck...

The most powerful application server on earth.
The only real POJO Application Server.
See it in Action :

To start a new topic, e-mail:
To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message