Java provides AtomicInteger
,AtomicLong
etc which basically compiles to CAS
instructions at hardware level. But why such AtomicXXX classes do not exist for other primitive types like short
and floating point numbers like float
and double
?
You can't CAS on less than a word. AtomicBoolean is implemented using an int
and float
could be implemented using an int
and double
using a long
.
AFAIK, these were added as part of Doug Lea's concurrency library being included and there hadn't been enough of a need to have Atmoic versions of these types before.
IMHO an AtomicDouble could be useful, but I avoid using float
whenever possible due to the lack of precision.
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