Tag

OptimisticLocking

1 views collected around this technical thread.

Selected Java Interview Questions
Selected Java Interview Questions
Jan 3, 2022 · Fundamentals

Understanding AtomicInteger: Optimistic Locking and CAS in Java

AtomicInteger provides a thread‑safe, lock‑free counter in Java by employing optimistic locking and CAS operations, offering higher efficiency than synchronized blocks; the article explains its motivation, usage examples, underlying Unsafe mechanisms, volatile semantics, and key methods such as incrementAndGet and compareAndSet.

AtomicIntegerCASJava
0 likes · 7 min read
Understanding AtomicInteger: Optimistic Locking and CAS in Java
Full-Stack Internet Architecture
Full-Stack Internet Architecture
Sep 22, 2020 · Backend Development

Understanding AtomicInteger, CAS, and Lock‑Free Concurrency in Java

This article explains how Java's AtomicInteger and related atomic classes provide lock‑free thread‑safe operations to replace non‑atomic constructs like i++, detailing their inheritance, underlying Unsafe mechanisms, CAS implementation, memory barriers, optimistic locking, the ABA problem, and practical code examples for increment, decrement, and custom CAS‑based locks.

AtomicIntegerCASJava
0 likes · 15 min read
Understanding AtomicInteger, CAS, and Lock‑Free Concurrency in Java