[concurrency-interest] Significance of volatile for Objects
mthornton at optrak.co.uk
Fri Mar 7 05:23:35 EST 2008
Peter Veentjer wrote:
> I know you made the remark, but for other less experienced developers
> reading this thread.. the example is not threadsafe because HashMap is
> not threadsafe. So its internal structure could be corrupted by
> concurrent access.
I think it would be safe provided no writes to the HashMap happen after
the volatile assignment, and that it was safely created prior to that
point. There are Map's which aren't threadsafe even for reading, but as
far as I know HashMap is not one of them.
More information about the Concurrency-interest