Is anybody aware of any real life use of the class AtomicLongFieldUpdate? I have read the description but I have not quite grasped the meaning of it. Why do I want to know that? Curiosity and for OCPJP preparation.
Thanks in advance.
You can think of a cost ladder for the following:
long
: cheap, but unsafe for multi-threaded accessvolatile long
: more expensive, safe for multi-threaded access, atomic operations not possibleAtomicLong
: most expensive, safe for multi-threaded access, atomic operations possible(When I say 'unsafe' or 'not possible' I mean 'without an external mechanism like synchronization' of course.)
In the case where multi-threaded access is needed, but most operations are simple reads or writes, with only a few atomic operations needed, you can create one static instance of AtomicLongFieldUpdate
and use this when atomic updates are needed. The memory/runtime overhead is then similar to a simple volatile
variable, except for the atomic operations which are of the order of (or slightly more expensive than) the ordinary AtomicLong
operations.
Here is a nice little tutorial.
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