Nice to @Share?

Joshua Bloch jjb at google.com
Mon Feb 22 14:29:13 PST 2010


Mark,

On Mon, Feb 22, 2010 at 1:59 PM, Mark Thornton <mthornton at optrak.co.uk>wrote:

> Joshua Bloch wrote:
>
>> Not so. Shared *mutable* state must be synchronized.  If it's not shared
>> *or
>> not mutable*, no synchronization is necessary.
>>
>>    Josh
>>
>>
> I understood that non mutable state actually has to be declared final if
> you want to share it across threads reliably without using synchronization.
> Merely not modifying it isn't sufficient.


This is a complex topic.  It turns out that if an object is "strongly
immutable" (like String), you can share references to it with no
synchronization whatsoever.If you're morbidly curious, this is a good place
to start: http://www.cs.umd.edu/~pugh/java/memoryModel/ .

           Josh


More information about the lambda-dev mailing list