tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <>
Subject Re: Question about resetting datasources and changes to the BasicDataSource.close() method
Date Fri, 01 Jun 2012 16:17:28 GMT
Hash: SHA1


On 6/1/12 11:54 AM, Hedrick, Brooke - 43 wrote:
>> -----Original Message----- From: Christopher Schultz
>> [] 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
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools -
Comment: Using GnuPG with Mozilla -


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message