Stats

102 Contributors: 4 Saturday, February 11, 2017
Licensed under: CC-BY-SA
Not affiliated with Stack Overflow
Rip Tutorial: riptutorial@gmail.com
Roadmap: roadmap
Download eBook

Atomic Types

Download java eBook

Introduction

Java Atomic Types are simple mutable types that provide basic operations that are thread-safe and atomic without resorting to locking. They are intended for use in cases where locking would be a concurrency bottleneck, or where there is risk of deadlock or livelock.

Parameters

ParameterDescription
setVolatile set of the field
getVolatile read of the field
lazySetThis is a store ordered operation of the field
compareAndSetIf the value is the expeed value then sent it to the new value
getAndSetget the current value and update

Remarks

Many on essentially combinations of volatile reads or writes and CAS operations. Best way to understand this is to look at the source code directly. E.g. AtomicInteger, Unsafe.getAndSet

Related Examples