Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java - Atomic access to field within object

Tags:

java

atomic

If I need atomic access to an int field inside an object, is it sufficient to declare the field as an AtomicInteger or do I need to use an AtomicIntegerFieldUpdater? (and why?)

like image 320
lgp Avatar asked Jul 12 '11 20:07

lgp


1 Answers

Using an AtomicInteger is sufficient. Atomic updaters are for use with volatile fields; the primary use case is data structures which have large numbers of fields that require atomic access; you use the field updater to use those fields with atomic semantics without having an AtomicInteger reference for each field.

For a detailed discussion, see this link.

like image 59
Paul Morie Avatar answered Sep 23 '22 16:09

Paul Morie