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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to