[concurrency-interest] Joda-Time immutability
scolebourne at joda.org
Tue Jun 21 07:49:57 EDT 2011
On 21 June 2011 09:11, Mark Thornton <mthornton at optrak.com> wrote:
> This should be backward compatible with existing serialized instances while
> allowing the fields in BaseDateTime to be final. It comes at the expense of
> a slightly larger MutableDateTime object, and slightly slower
In the end, I think Doug's advice is probably right. Just use
volatile. I don't think its ideal, but it "Just Works", which is a
good thing in this codebase.
Mark, I think your change would work (and I like the neat set before
defaultReadFields). However it would have required any mutable
application subclass to be changed, which I was hoping to avoid.
Compared to the volatile approach I decided simple is best.
Another variation which would also appear to work would be to change
the data storage in BaseDateTime to a transient final two element
array and use ObjectStreamField to read and write the existing
serialized format. (The final array would presumably keep immutability
happy, while the array settability even when final would keep the
mutable classes happy). But the complexity was considerably greater,
so volatile won (unless someone screams that it kills their
Thanks everyone for your thoughts.
More information about the Concurrency-interest