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;
}
}
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;
}
}
> Date: Thu, 18 Sep 2008 11:56:33 -0400
> From: [EMAIL PROTECTED]
> To: [email protected]
> Subject: Re: Tomcat 5.5, JNDI Connection Pooling, Active connections keep
> increasing....
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> sinoea,
>
> sinoea kaabi wrote:
> > The static methods are not thread-safe you say!
>
> No, your static methods are perfectly threadsafe. Johnny is just getting
> itchy because it's not what he'd do. You aren't using any class-level
> members in your static methods so you should be fine.
>
> > Or in fact, you must be right, should I declare them synchronized?
>
> No! This will limit your code to serialized database access, in which
> case you are really only allowing a single connection to be used at a time.
>
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.9 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iEYEARECAAYFAkjSejEACgkQ9CaO5/Lv0PDPUACggEWdUUKYajU1uRr8YgO/u+2J
> //gAoLGPZqMvl6WDyEKQWnNkYpV2Tdrp
> =ewSc
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: [email protected]
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
_________________________________________________________________
Win New York holidays with Kellogg’s & Live Search
http://clk.atdmt.com/UKM/go/111354033/direct/01/