|
The Atomic classes in Java 5
In our outline of how synchronization works,
we saw that under the hood, a machine instruction generally called Compare-And-Swap (CAS)
was used to effectively read and write to a memory location at the same time. From Java 5 onwards,
CAS and related instructions are effectively exposed at the level of the Java programmer in the form of a
series of "atomic" classes in the java.util.concurrent package:
- Classes providing atomic access to main primitive types or to an object
reference: AtomicBoolean, AtomicInteger and AtomicLong, AtomicReference;
- Classes providing atomic access to fields in arrays of the correspoding types: AtomicIntegerArray,
AtomicLongArray, AtomicReferenceArray;
- Classes to atomically couple a boolean or integer with a reference field:
AtomicMarkableReference and AtomicStampedReference;
- Atomic field updaters: classes to wrap up atomic access, via reflection, to volatile fields of another
class (AtomicIntegerFieldUpdater, AtomicLongFieldUpdater and
AtomicReferenceFieldUpdater);
- Concurrent collection classes, including significantly
a highly concurrent hash map
implementation.
Unless otherwise stated, the Java programming articles and tutorials on this site are written by Neil Coffey.
Suggestions are always welcome if you wish to suggest topics for Java tutorials or programming articles,
or if you simply have a programming question that you would like to see answered on this site. Most topics
will be considered. But in particular, the site aims to provide tutorials and information on topics that
aren't well covered elsewhere, or on Java performance information that is poorly described or understood.
Suggestions may be made via the Javamex blog (see the site's front page for details).
Copyright © Javamex UK 2009. All rights reserved.
|