Also I think the article quoted predates java 5 which (I think) makes
double checked locking safe for "volatile" ivars??
Andrus
On Jan 2, 2008, at 11:51 PM, Tore Halset wrote:
> Hello.
>
> Interesting. Is it possible to use the "Making it work for static
> singletons" variant to get rid of the synchronization?
>
> Btw, this is also very well described in "Effective Java Programming
> Language guide" by Joshua Bloch - a must-have book for me.
>
> - Tore.
>
> On Jan 2, 2008, at 22:26, mgentr..pache.org wrote:
>
>> Author: mgentry
>> Date: Wed Jan 2 13:26:15 2008
>> New Revision: 608235
>>
>> URL: http://svn.apache.org/viewvc?rev=608235&view=rev
>> Log:
>> Removed double-checked locking of queryCache. See http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html
>> for details.
>>
>> Modified:
>> cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/
>> java/org/apache/cayenne/access/DataContext.java
>>
>> Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/
>> src/main/java/org/apache/cayenne/access/DataContext.java
>> URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataContext.java?rev=608235&r1=608234&r2=608235&view=diff
>> =
>> =
>> =
>> =
>> =
>> =
>> =
>> =
>> =
>> =====================================================================
>> --- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/
>> main/java/org/apache/cayenne/access/DataContext.java (original)
>> +++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/
>> main/java/org/apache/cayenne/access/DataContext.java Wed Jan 2
>> 13:26:15 2008
>>.. -257,16 +257,11 @@
>> *
>> *..ince 3.0
>> */
>> - public QueryCache getQueryCache() {
>> -
>> + public synchronized QueryCache getQueryCache() {
>> if (queryCache == null) {
>> - synchronized (this) {
>> - if (queryCache == null) {
>> - queryCache = getParentDataDomain()
>> - .getQueryCacheFactory()
>> - .getQueryCache(Collections.EMPTY_MAP);
>> - }
>> - }
>> + queryCache = getParentDataDomain()
>> + .getQueryCacheFactory()
>> + .getQueryCache(Collections.EMPTY_MAP);
>> }
>>
>> return queryCache;
>>.. -277,7 +272,7 @@
>> *
>> *..ince 3.0
>> */
>> - public void setQueryCache(QueryCache queryCache) {
>> + public synchronized void setQueryCache(QueryCache queryCache) {
>> this.queryCache = queryCache;
>> }
>>
>>
>>
>>
>
>
This archive was generated by hypermail 2.0.0 : Wed Jan 02 2008 - 17:16:28 EST