I'm wondering what kind of performance penalty there is, if any, when doing a full lookup of the Datasource object each and every time through JNDI calls? Basically, does it make sense to do one lookup and store a local copy for future use? The one problem I see with doing that is that if one ever wants to use the Tomcat Manager app to modify configuration on the fly, using the local copy of the Datasource would make it so you never really realize that a change to configuration has been made. Am I simply losing flexibility without gaining any performance?

The way I have the lookup performed is the following. Please let me know if this is totally unnecessary....

final class MyDataSourceClass {

private static DataSource ds = null;
public static Boolean DS_INITIALIZED = Boolean.FALSE;

public static Connection getConnection() throws SQLException {
if (DS_INITIALIZED.equals(Boolean.FALSE) || ds == null) {
synchronized (DS_INITIALIZED) {
if (DS_INITIALIZED.equals(Boolean.FALSE) || ds == null) {
try {
Context ctx = new InitialContext();
ds = (DataSource)ctx.lookup("java:comp/env/jdbc/myDB");
if (ds == null) throw new SQLException("No DataSource available for Connection");
DS_INITIALIZED = Boolean.TRUE;
}
catch (NamingException ne) {
throw new SQLException("JNDI Lookup Failed: " + ne.getMessage());
}
}
}
}
return ds.getConnection();
}

public static void returnConnection(Connection conn) throws SQLException {
conn.close();
}

}

So, basically I want to know if the lookup isn't expensive enough to bother with storing the DataSource locally.

thanks,

Jake


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

Reply via email to