commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sebb <seb...@gmail.com>
Subject Re: Trouble with commons-math
Date Thu, 01 Nov 2007 12:43:16 GMT
On 01/11/2007, Brent Worden <brent.worden@gmail.com> wrote:
> On Oct 31, 2007 6:41 AM, sebb <sebbaz@gmail.com> 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: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Mime
View raw message