-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Ric,

On 10/26/14 2:31 PM, Ric Bernat wrote:
> Thanks, Nevin. I certainly appreciate your deep treatment of my
> question/issue!
> 
> I would like to ask for clarification about a point in your #2:
> 
>> (2) CONTAINER-MANAGED CONNECTION POOL. (a) using container
>> injection
>> 
>> @Resource(name="....") private DataSource datasource
>> 
>> (b) traditional JNDI lookup
>> 
>> Context naming = new InitialContext(); DataSource datasource =
>> (DataSource) naming.lookup("....");
> 
> With either 2a or 2b, for a given JNDI resource name, regardless of
> where in my JAX-RS Java code I get the DataSource, I can be certain
> that I am getting a DataSource/connection from a container-managed
> connection pool, and so there is no need to cache anything within
> my application, right?
> 
> The only stumbling block for me is that in our application,
> databases are added at runtime, and I don't believe there is a way
> to add a JNDI Resource definition at runtime (i.e.,
> <GlobalNamingResources> or <Context> element of particular
> application). Since databases are not added rapid-fire, I suppose
> each time one is added I could dynamically generate a new server
> configuration file under a temporary name, adding Resources for all
> databases, then run a script that shuts down Tomcat, replaces the
> server configuration copy with the newly generated one, and restart
> Tomcat. A little clumsy, I suppose, but the benefit would be
> significant.
> 
>> (3) APPLICATION-MANAGED CONNECTION POOL.
> 
> Alternatively, I can manage my own cache of connection pools (i.e.,
> org.apache.tomcat.jdbc.pool.DataSource instances), keyed off of
> database name in a HashMap, for example, and storing that cache in
> an object that is persisted across web service calls (using JAX-RS
> Features). Do you see any problem with retaining
> org.apache.tomcat.jdbc.pool.DataSource instances in memory and
> re-using them for extended periods of time?

None!

The JNDI implementation in Tomcat is essentially a hash map, so you
would be doing something very similar to what Tomcat already provides.

You could even inject your own DataSource objects into Tomcat's JNDI
map and then your application would be a little bit more "standard".

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
Comment: GPGTools - http://gpgtools.org

iQIcBAEBCAAGBQJUT3pkAAoJEBzwKT+lPKRYVfYP/jWD0jwiItI3AfznC0eRDP5Y
ZnHuj271D80n0c5hDG1UUGnDRes4UMP4hTgFEzge0phkh0bB0PMCwpTMNdDNANc8
vEVlpdSDGnHkO9O2cPMXIOlw2peyW+SBLO7FCJ08Np5pLhkI0bIXNvw844ghRZcw
sdnqwYhX6oJnN+0U1DfS0/IWPjWlkTj2dDM6brZGXUOCPVf07Tyga/IPpsaIZjDI
+fHNT1s9rMVHigY+G8JJMLSBMb4+i8YKWVom9cwCDphPSEVR4nWPPQihgPdSj0tw
lIb3h14N3WoARDmyyIX8lSkM+lSNPiPFyUEBj85OKXl/EyMWfFCR/1VIPoQRJNdG
zFh+F+Y6SxQOpp8sA7lCJf9xQ2sRmhoP994q9ewvUgYsGtu4h9mWxaeWbSpDDD+M
K2IAtu2zNbaQN9+YOKMlvMpOFOBmdh2aSPcFqK9OKYk9CD0dX+XriOrd10ernn0A
lrJVrAPMx3qZMGW1UKkTD9wRGMV9v9Z1/BgQd7XOcKIcioYZL2OoxFBTr+zPRBWU
tPU0Pa/wmD2InFKRXVf9WgQq9+awpmPSHkSmBeJYdOm6hMil5XxxObZyu3I36RSS
Hrv5w2HKg4xuYTkioIQP3Cl+9WvkoTsVgnpyb0PEo7SN3biAEU4exh2uu2qq2bb1
V9UwKJd+9AfwsK7KkTJr
=EqSN
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to