----- Original Message -----
From: "Christopher Schultz" <[EMAIL PROTECTED]>
To: "Tomcat Users List" <users@tomcat.apache.org>
Sent: Monday, September 22, 2008 3:14 PM
Subject: Re: Tomcat 5.5, JNDI Connection Pooling, Active connections keep
increasing....
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Sinoea,
sinoea kaabi wrote:
Christopher Schultz wrote:
You aren't using any class-level members in your static methods so
you should be fine.
This means that I cannot declare a:
public class Data {
private static DataSource datasource = null;
public static DataSource getDataSource() {
if (datasource == null) {
// create a datasource
}
return datasource;
}
}
Well, you /can/, but it wouldn't be a very good idea.
In the code above the class-level member is the datasource.
Do you mean I should do like this instead:
public class Data {
public static DataSource getDataSource() {
// create a new datasource for each call to this method
return datasource;
}
}
Assuming that the 'datasource' object is still shared among threads,
it's still a bad idea. DataSource objects are not guaranteed to be
threadsafe, so you shoule not share them.
This is a bad example, because you should never cache the DataSource in
the first place: you should always get it from the JNDI tree.
- -chris
Ah... thanks Chris.... being able to
DataSource ds =
(DataSource)initContext.lookup("java:/comp/env/jdbc/xmecsDB");
from anywhere in the webapp would solve a lot of problems in that code...
Thanks...
---------------------------------------------------------------------------
HARBOR : http://www.kewlstuff.co.za/index.htm
The most powerful application server on earth.
The only real POJO Application Server.
See it in Action : http://www.kewlstuff.co.za/cd_tut_swf/whatisejb1.htm
---------------------------------------------------------------------------
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]