[concurrency-interest] Primitives wrappers and visibility problems

Peter Veentjer alarmnummer at gmail.com
Wed Aug 23 06:43:13 EDT 2006

If the field isn't final, it could be subject to out of order reads
and writes, meaning that a different thread could see a partially
created object -> not threadsafe.

If I'm missing something, please enlighten me :) The subject is very
interesting and the best way to get a better understanding is to ask

On 8/23/06, Joe Bowbeer <joe.bowbeer at gmail.com> wrote:
> On 8/23/06, Peter Veentjer <alarmnummer at gmail.com> wrote:
> > I have another question about visibility problems. Someone suggested
> > to me that the primitve wrappers (like Integer) don't use a final
> > field for the primitive they contain. This would make them not
> > threadsafe. Is this correct?
> In Java 5, Integer *does* use a final.  See below.
> If it didn't use final, then it would still be thread safe -- because
> it is immutable.  But it would not be immune to unsafe publication.
>    private final int value;
>    public Integer(int value) {
>        this.value = value;
>    }
> --Joe
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at altair.cs.oswego.edu
> http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest

More information about the Concurrency-interest mailing list