[concurrency-interest] Primitives wrappers and visibility problems

Joe Bowbeer joe.bowbeer at gmail.com
Wed Aug 23 05:55:51 EDT 2006


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


More information about the Concurrency-interest mailing list