On 01/11/2007, Brent Worden <[EMAIL PROTECTED]> wrote:
> On Oct 31, 2007 6:41 AM, sebb <[EMAIL PROTECTED]> wrote:
> >
> > However, I'm not sure that the class is thread-safe.
> > For example the windowSize field is not final, and therefore may not
> > be visible to all threads after construction. Making it final would
> > fix this.
> >
> > Fixing the eDA field might be tricky.
> >
>
> I don't think this is a problem because no object reference to the
> SynchronizedDescriptiveStatistics instance is published to other
> objects during construction.  The first time an object reference is
> made available to other objects (and other threads) is after the
> constructor returns a new object.  At which time, the object is fully
> constructed and all instance variables have been initialized.
>

That's what I used to think, but then I read up on JSR133 and it seems
that non-final fields are not necessarily flushed to memory.

See for example Problem #1 in

http://www.ibm.com/developerworks/java/library/j-jtp02244.html?S_TACT=105AGX02&S_CMP=EDU

As I understand it, only final fields are guaranteed to be made
visible to other threads in the absence of any other synchronisation.

Note that Java 1.5 changes the String implementation to use final
fields. If that were not necessary, why was it done?

> Thanks,
>
> Brent.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to