commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stephen Colebourne <>
Subject Re: svn commit: r819141 - in /commons/proper/lang/trunk/src: java/org/apache/commons/lang/concurrent/ test/org/apache/commons/lang/concurrent/ test/org/apache/commons/lang/concurrent/
Date Sat, 26 Sep 2009 23:01:12 GMT
>> Is the temporary variable "result" needed?
>> Or maybe I'm missing some subtlety here ?
>> In which case it should be documented in a comment please.
>> <snip/>
> According to Bloch's book the temporary variable is indeed a performance 
> optimization. It prevents that the volatile field is read twice in the 
> common case that the object has already been initialized.

Its not about performance. Without the local variable, the pattern is 
unsafe concurrently. The pattern must be followed exactly (including the 
double assign) in order for the locking to be concurrent-safe.


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

View raw message