Hacker News new | ask | show | jobs
by the8472 2585 days 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.

1 comments

For primitives Java uses special CPU instructions. In the Atomic* package. It's not recommended for plain objects.