tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Smith <>
Subject Re: JNDI/Tomcat question from newbie
Date Thu, 01 Sep 2005 14:46:39 GMT
Personally, I'd just keep a reference to the datasource around maybe as
a class instance variable.  It doesn't constitute a connection in and of
itself -- just a way of getting one from the pool.  Connections on the
other hand should be explicitly closed as soon as they aren't needed
anymore in any method that get's one.


Hyatt, Gordon wrote:

>Hello All,
>I'm a newbie to database pooling via JNDI and I have a JNDI/Tomcat question (more of a
"best practices"/most scalable/fastest performance/least resource consumption type of question).
>Each time the JNDI resource (pooled database connection) is needed, should a complete
JNDI lookup be performed or can part of the lookup be "cached"?  For example, should the code
>Context initCtx = new InitialContext ();
>Context envCtx = (Context)initCtx.lookup ("java:comp/env");
>ds = (DataSource)envCtx.lookup ("jdbc/data_source_name");
>or can the java:comp/env Context be saved as an attribute in the servlet context and a
(synchronized) code segment like the following be used to obtain the DataSource?
>Context ctx = (Context)ctxFromServletContext.lookup ("");
>ds = (DataSource)ctx.lookup ("jdbc/data_source_name");
>Thus far, I haven't read anything about which method is acceptable/preferred or if one
method yields significant performance benefit.  
>Since, according to the docs a Context is not guaranteed to be synchronized against concurrent
access by multiple threads, I assume that the first code segment above should be synchronized,
especially if it is in a static method.
>Thanks in advance,
>To unsubscribe, e-mail:
>For additional commands, e-mail:

David Smith
Network Operations Supervisor
Department of Entomology
College of Agriculture & Life Sciences
Cornell University
2132 Comstock Hall
Ithaca, NY  14853
Phone: 607.255.9571
Fax: 607.255.0939

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message