tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Johnny Kewl" <j...@kewlstuff.co.za>
Subject Re: Tomcat 5.5, JNDI Connection Pooling, Active connections keep increasing....
Date Mon, 22 Sep 2008 15:08:25 GMT

----- Original Message ----- 
From: "Christopher Schultz" <chris@christopherschultz.net>
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: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message