[concurrency-interest] Significance of volatile for Objects

Mark Thornton mthornton at optrak.co.uk
Fri Mar 7 05:23:35 EST 2008


Peter Veentjer wrote:
> PS:
> 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.

Mark Thornton



More information about the Concurrency-interest mailing list