[concurrency-interest] do constructors ever involve threading under the covers?

Aleksey Shipilev aleksey.shipilev at oracle.com
Wed Oct 3 10:49:30 EDT 2012


On 10/03/2012 06:37 PM, Andy Nuss wrote:
> For clarification, lets say a caller passes my constructor an ArrayList
> with seeded values.
> 
> class EffectivelyImmutableArrayListWrapper {
>     private volatile ArrayList  mylist;
>     EffectivelyImmutableArrayListWrapper (ArrayList list)
>     {
>           // .... create mylist and copy all values from list into mylist
>           // this class only provides getters for mylist
>           // mylist never changes except in this constructor where
> created and filled
>     }
> 
>     // getter functions for mylist
> }
> 
> From the above snippet, we see that we are attempting to provide a
> publishing wrapper/snapshot for an ArrayList.  Is "volatile" necessary
> here?  

It wouldn't help if $list passed in constructor is published unsafely.
It's too late for EffectivelyImmutableArrayListWrapper to do anything
about it.

-Aleksey.





More information about the Concurrency-interest mailing list