Maier Holger wrote:
Wouldn't it be better to read the
data source once in a singleton class
and then just get it back, i.e.

I did the same thing with my application where I did a key/value storage
object that was a singleton in my ServletContext.  I did notice a slight
speed improvement and I've had zero issues.

//example factory configured by properties file
DataSourceFactory dsf =
DataSourceFactory.getInstance(servlet.getServletContext());
DataSource ds = dsf.getDataSource("hrdb");


Jacob Hookom
CS Student
University of Wisconsin, Eau Claire
===================================
http://www.swanked.net
you're not hip enough yet

-----Original Message-----
From: Maier Holger, ITS-AKIS [mailto:[EMAIL PROTECTED]] 
Sent: Monday, July 15, 2002 9:29 AM
To: 'Tomcat Users List'
Subject: DataSource Access - Design Question

Hi,
I am trying to get my DataSource 
(with Connection Pooling) to run.

In the examples one always gets the 
DataSource from JNDI and I have the 
impression that everytime I want
to get my connection from DataSource
via a Context lookup.

Wouldn't it be better to read the
data source once in a singleton class
and then just get it back, i.e. 

private DataSource ds;
...
public static void getDataSource() {
   // if data source unknown read it from context
   if (ds == null) {
     try {
       Context ctx = new InitialContext();
       ds = (DataSource) ctx.lookup("java:comp/env/jdbc/myDataSource");
     }
     catch (..) {..}
   }
 
   return ds;                   
}

This should be faster than accessing the context
every time you need a datasource or a connection.

Could this lead into problems?
Any suggestions?

Cheers,
Holger

-----------------------------------------------------
Holger Maier      Tel.:  (06831) 47-3497
ITS-AKIS          eMail: [EMAIL PROTECTED]

AG der Dillinger Hüttenwerke
Postfach 1580
66748 Dillingen


--
To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>

---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.375 / Virus Database: 210 - Release Date: 7/10/2002
 

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.375 / Virus Database: 210 - Release Date: 7/10/2002
 


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to