-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Mikolaj,

Mikolaj Rydzewski wrote:
| JNDI lookups are expensive.

No, they're not. We're not talking about using a remote JNDI server or
AD or anything like that. This is all local and the lookups are very fast.

To convince yourself, run this simple JSP:

<%@ page
~    import="javax.naming.*"
%>
<%
~    int iterations = 10000;
~    long start = System.currentTimeMillis();

~    for(int i=0; i<iterations; ++i)
~    {
~        Context ctx = new InitialContext();
~        ctx.lookup("java:comp/env/jdbc/diagnosis");
~    }

~    long elapsed = System.currentTimeMillis() - start;
%>
<%= iterations %> lookups took <%= elapsed %>ms, average = <%=
(double)elapsed / (double)iterations %>ms.

On my dev machine (AMD Athlon XP 1700+, default 64MB heap), these
statistics are printed by this JSP:

10000 lookups took 442ms, average = 0.0442ms.

That's pretty fast. Database queries are slow, not JNDI lookups.

| You should get DataSource object from JNDI
| first, and then pass it to other threads. Every thread should just call
| DataSource.getConnection().

That's a bad idea. The reason you store the DataSource in JNDI is so
that it is universally available and replaceable. Caching the DataSource
somewhere else is counter-productive.

- -chris

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkf82bIACgkQ9CaO5/Lv0PC5jACgkAWrgv4G1nbbxm8SGUJxnHsa
4fUAoMLU6W4lGlO5khaI2xwfbWLMpvk8
=j/sF
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to