atomic variable
A variable, such as AtomicInteger, whose updates like incrementAndGet happen as one indivisible step that no other thread can interrupt.
In more detail
Atomic classes in java.util.concurrent.atomic fix simple races on a single value without a lock. They do not protect an invariant that spans several variables; that needs a lock.
Example
counter.incrementAndGet();Related terms
- race condition — A bug whose outcome depends on the timing of two things happening at once.
- synchronized — The Java keyword that lets only one thread at a time run a block of code guarded by the same lock object.
Taught in
- Concurrency Basics: Threads And Runnable — Modern Java: Virtual Threads & High-Throughput Services
- Thread Safety: Locks And Atomics — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Sprint: Modules And Concurrency — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep