Tag

AtomicInteger

1 views collected around this technical thread.

FunTester
FunTester
May 26, 2025 · Backend Development

Thread‑Safe Round Robin Load Balancer Using Java AtomicInteger

This article explains how to implement a thread‑safe round‑robin load balancer in Java using AtomicInteger, discusses its advantages and limitations, provides sample code for single‑thread and multithreaded scenarios, and suggests further optimizations such as health checks, weighted routing, and dynamic server updates.

AtomicIntegerJavaLoad Balancing
0 likes · 11 min read
Thread‑Safe Round Robin Load Balancer Using Java AtomicInteger
FunTester
FunTester
Dec 3, 2024 · Backend Development

Why i++ Is Not Thread‑Safe and How to Demonstrate It with Java, Byteman, and Synchronization

The article explains that the Java increment operation i++ is not atomic, describes the three‑step execution that leads to race conditions in multithreaded environments, and shows how to reproduce and fix the issue using synchronized blocks, AtomicInteger, and Byteman fault‑injection scripts.

AtomicIntegerBytemanJava
0 likes · 10 min read
Why i++ Is Not Thread‑Safe and How to Demonstrate It with Java, Byteman, and Synchronization
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
Architecture Digest
Architecture Digest
Aug 14, 2021 · Backend Development

Solving Duplicate Order Number Issues in High-Concurrency Java Applications

After encountering duplicate order IDs during a system upgrade, the author analyzes the shortcomings of the original timestamp-and-random-based generator, demonstrates concurrency tests revealing collisions, and presents a revised Java implementation using atomic counters, shortened timestamps, and IP suffixes to reliably produce unique order numbers even under high load.

AtomicIntegerJavabackend development
0 likes · 9 min read
Solving Duplicate Order Number Issues in High-Concurrency Java Applications
Full-Stack Internet Architecture
Full-Stack Internet Architecture
Jul 10, 2021 · Backend Development

Concurrent Unit Testing of AssetService.update with Optimization Techniques

This article explains how to write a concurrent unit test for the AssetService.update method using thread pools, CountDownLatch, AtomicInteger, and then suggests optimizations such as replacing AtomicInteger with LongAdder and employing CyclicBarrier to increase contention, providing full code examples and detailed explanations.

AtomicIntegerCyclicBarrierJava
0 likes · 9 min read
Concurrent Unit Testing of AssetService.update with Optimization Techniques
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
Architect's Tech Stack
Architect's Tech Stack
Sep 20, 2020 · Fundamentals

Is i++ Thread‑Safe? Understanding Volatile, Visibility, and Atomic Operations in Java

This article explains why the i++ operation is not thread‑safe in Java, examines how the volatile keyword affects variable visibility, demonstrates the problem with concrete code examples, and shows how to solve it using synchronized blocks or the java.util.concurrent.atomic classes.

AtomicIntegerJavaThread Safety
0 likes · 7 min read
Is i++ Thread‑Safe? Understanding Volatile, Visibility, and Atomic Operations in Java
Full-Stack Internet Architecture
Full-Stack Internet Architecture
Aug 26, 2020 · Backend Development

Testing Volatile Thread Safety and Comparing LongAdder vs AtomicInteger Performance in Java

This article examines the thread‑safety of the volatile keyword under multi‑write scenarios, demonstrates its failure with a concurrent counter test, and benchmarks LongAdder against AtomicInteger using JMH, revealing LongAdder’s superior performance under high contention and AtomicInteger’s advantage in low‑contention environments.

AtomicIntegerJMHJava
0 likes · 8 min read
Testing Volatile Thread Safety and Comparing LongAdder vs AtomicInteger Performance in Java
Wukong Talks Architecture
Wukong Talks Architecture
Aug 21, 2020 · Fundamentals

Understanding Java CAS (Compare‑And‑Swap) with Code Examples and Debugging

This article explains Java's Compare-And-Swap (CAS) mechanism, illustrates its usage with AtomicInteger code examples, walks through step‑by‑step debugging of CAS operations, and discusses its advantages, limitations such as the ABA problem and spin‑wait overhead.

AtomicIntegerCASJava
0 likes · 11 min read
Understanding Java CAS (Compare‑And‑Swap) with Code Examples and Debugging
Full-Stack Internet Architecture
Full-Stack Internet Architecture
Jul 23, 2020 · Fundamentals

Understanding CAS, AtomicInteger, and Unsafe in Java Concurrency

This article explains Java's memory model, the limitations of synchronized and volatile, introduces the java.util.concurrent.atomic package, details the CAS algorithm, the role of the Unsafe class, common pitfalls like the ABA problem, and presents code examples and solutions such as AtomicStampedReference.

ABAAtomicIntegerCAS
0 likes · 15 min read
Understanding CAS, AtomicInteger, and Unsafe in Java Concurrency
FunTester
FunTester
Feb 16, 2020 · Operations

Load Testing Proportional Login Methods with Java Concurrency and AtomicInteger

The article presents a detailed solution for load‑testing two login mechanisms—username/password and phone‑code—by creating a thread‑safe user pool, using AtomicInteger for proportion control, marking each request, and providing complete Java scripts for the test framework, login APIs, and password encryption.

AtomicIntegerJavaconcurrency
0 likes · 8 min read
Load Testing Proportional Login Methods with Java Concurrency and AtomicInteger
Mike Chen's Internet Architecture
Mike Chen's Internet Architecture
Jun 24, 2019 · Backend Development

Understanding Java Thread Locks: synchronized, ReentrantLock, Semaphore, and AtomicInteger

This article explains why multithreading is needed, outlines the challenges of concurrent access, and provides a detailed overview of four Java thread lock mechanisms—synchronized, ReentrantLock, Semaphore, and AtomicInteger—along with their characteristics, usage patterns, and performance considerations.

AtomicIntegerJavaReentrantLock
0 likes · 9 min read
Understanding Java Thread Locks: synchronized, ReentrantLock, Semaphore, and AtomicInteger
Full-Stack Internet Architecture
Full-Stack Internet Architecture
Jun 15, 2019 · Fundamentals

Understanding Java Multithreading: Threads, Concurrency, and Atomic Operations

This article introduces Java multithreading by explaining the relationship between processes and threads, the benefits of concurrency, common pitfalls like race conditions, and how to safely manage shared variables using ThreadPoolExecutor, AtomicInteger, volatile, and CAS operations.

AtomicIntegerCASJava
0 likes · 11 min read
Understanding Java Multithreading: Threads, Concurrency, and Atomic Operations