[concurrency-interest] Should I avoid compareAndSet with value-based classes?

Andrew Haley aph at redhat.com
Fri Jul 7 05:32:05 EDT 2017

On 07/07/17 10:23, Alex Otenko wrote:
> No, not only updates, but reads, too.
> If you assume non-atomic updates, the problem becomes just like with
> volatile long - has to use synchronized block for all accesses.

No.  There is one reference to the Instant, reference updates are
atomic, and Instant itself is immutable, so none of its state becomes
visible before all of its fields are initialized.  I do not believe
that it is necessary for readers to be synchronized.

Andrew Haley
Java Platform Lead Engineer
Red Hat UK Ltd. <https://www.redhat.com>
EAC8 43EB D3EF DB98 CC77 2FAD A5CD 6035 332F A671

More information about the Concurrency-interest mailing list