tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Hyatt, Gordon" <Gordon.Hy...@joslin.harvard.edu>
Subject JNDI/Tomcat question from newbie
Date Thu, 01 Sep 2005 14:17:48 GMT
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 be:

<code>
Context initCtx = new InitialContext ();
Context envCtx = (Context)initCtx.lookup ("java:comp/env");
ds = (DataSource)envCtx.lookup ("jdbc/data_source_name");

</code>

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?

<code>
Context ctx = (Context)ctxFromServletContext.lookup ("");
ds = (DataSource)ctx.lookup ("jdbc/data_source_name");
</code>

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,

Gord 

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message