Nice to @Share?
Zdenek Tronicek
tronicek at fit.cvut.cz
Tue Feb 23 00:08:22 PST 2010
Joshua Bloch napsal(a):
>> 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/ .
In some sense, Mark is right. Of course, you can share strongly immutable
objects without any synchronization. But how to share the reference? If
one thread stores a reference to a shared variable, how do you ensure that
such change is visible in another thread? You need a barrier and this is
probably where the hint "make the shared variables final" comes from.
Z.
--
Zdenek Tronicek
FIT CTU in Prague
More information about the lambda-dev
mailing list