4 ms·
The standard pattern for working with atomics in java (volatiles are of limited use without atomic field updaters or varhandles) is to read it into a local vari
by the8472 7y ago
The standard pattern for working with atomics in java (volatiles are of limited use without atomic field updaters or varhandles) is to read it into a local variable, operate on that and only write it back to the volatile once you're done.
That has many benefits, among them the ability to store its value in registers.
- nullwasamistake 7y agoFor primitives Java uses special CPU instructions. In the Atomic* package. It's not recommended for plain objects.