My preference is just to use volatile. AtomicReference is basically some
fancy wrapper on top of it that _in this case_ wouldn't add value. I
understand volatile.
~ David Smiley
Apache Lucene/Solr Search Developer
http://www.linkedin.com/in/davidwsmiley
On Wed, Mar 17, 2021 at 10:52 AM
It looks like since jdk 1.5, making the array reference volatile will
prevent re-ordering array element writes (with respect to the volatile
array reference write):
https://web.archive.org/web/20200923063441/https://www.ibm.com/developerworks/library/j-jtp03304/index.html
So the code as initially
Hi,
I agree with Dawid to make it developer friendly. Most synchronized-blocks are
rmeoved by Hotspot anyways, so better safe than sorry!
David: I missed in your original mail that you were afraid of changes inside
the array not being visible. You can prevent that with fences, but all of that
Unless this code is used millions of millions of times I would just use a
code pattern that is understood by any developer - senior and junior... A
volatile or even initialization under a plain monitor. Those fancy memory
guards are great for low-level data structures but they are really hard to