-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Brooke,

On 6/1/12 11:54 AM, Hedrick, Brooke - 43 wrote:
>> -----Original Message----- From: Christopher Schultz
>> [mailto:ch...@christopherschultz.net] Sent: Thursday, May 31,
>> 2012 5:23 PM
> 
> That's what I will submit to commons-dbcp, then.
> 
>> On the one hand, synchronizing these methods should not be
>> necessary because Java boolean values are defined to be 32-bit
>> integers which feature atomic assignment (that is, no thread ever
>> sees only 8-bits of the 32-bit value being assigned and 24-bits
>> of the old value). On the other hand, threads are allowed to keep
>> cached copies of certain data under certain conditions. Using the
>> keyword 'volatile' /should/, in recent JVMs, make the use of 
>> 'synchronized' completely unnecessary, while older JVMs may even
>> ignore 'volatile' making 'synchronized' mandatory. Use of
>> 'synchronized' is the safest bet because it definitely causes a
>> 'memory barrier' to be crossed in any version of JVM: that means
>> that the thread is required to synchronize (perhaps a bad choice
>> of words) its cache with main memory which means that all
>> variables get the latest copies of the "real" data.
> 
> Yep.  That was my point too.  What does it really matter anyway 
> whether you are able to lock "this" in a getter.   When you ask
> for the value, you are just asking for what is current.  You have
> to protect yourself from non-initialized/null in any case.  It just
> adds some unnecessary overhead ( to the JVM and brain ) to
> synchronize your getter when it doesn't mutate the data - unless I
> am missing something.

Locking "this" makes sure that the thread's local copy of
whatever-you-are-getting is updated properly and not stale-cached. If
you synchronize the setter, it is a very good idea to synchronize the
getter too.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk/I6xcACgkQ9CaO5/Lv0PA87wCeLBo6OzS2H/oEq9pEEduhYNnV
xFEAn1sPEI8bUvvC2HSQKKb9Z5tpMQ4b
=vMfh
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to