When is it a good idea to use AtomicReferenceArray
? Please explain with an example.
looks like it's functionally equivalent to AtomicReference[]
, occupying a little less memory though.
So it's useful when you need more than a million atomic references - can't think of any use case.
If you had a shared array of object references, then you would use an AtomicReferenceArray
to ensure that the array couldn't be updated simultaneously by different threads i.e. only one element can be updated at a time.
However, in an AtomicReference[]
(array of AtomicReference
) multiple threads can still update different elements simulateously, because the atomicity is on the elements, not on the array as a whole.
More info here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With