tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <ch...@christopherschultz.net>
Subject Re: Tomcat 5.5, JNDI Connection Pooling, Active connections keep increasing....
Date Mon, 22 Sep 2008 13:14:39 GMT
-----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

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

iEYEARECAAYFAkjXmj8ACgkQ9CaO5/Lv0PDlcgCdFNuTHa9TJL8zLKfKCTMWEn0+
n38AniRE9T74fDioAZeOuVI/HbZlYIf+
=rQsW
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
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