Tagged articles
24 articles
Page 1 of 1
Selected Java Interview Questions
Selected Java Interview Questions
Feb 26, 2026 · Backend Development

Why Your Snowflake‑Like ID Generator May Duplicate IDs Under High Concurrency

The article analyzes a custom TraceIdGenerator that uses a simple AtomicInteger counter and IP‑based prefix, identifying how its reset logic and CAS competition can cause duplicate IDs in high‑concurrency scenarios, and proposes timestamp checks, larger ranges, retry mechanisms, and true Snowflake implementation as solutions.

AtomicIntegerID generationSnowflake algorithm
0 likes · 11 min read
Why Your Snowflake‑Like ID Generator May Duplicate IDs Under High Concurrency
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.

AtomicIntegerBackendRound Robin
0 likes · 11 min read
Thread‑Safe Round Robin Load Balancer Using Java AtomicInteger
Senior Brother's Insights
Senior Brother's Insights
Jul 21, 2022 · Backend Development

Mastering Java CAS: How AtomicInteger Achieves Lock‑Free Concurrency

This article explains the fundamentals of Compare‑And‑Swap (CAS), its implementation in Java through the Unsafe class, demonstrates AtomicInteger's lock‑free operations, and discusses CAS drawbacks such as spin‑wait overhead, single‑variable limitation, and the ABA problem with mitigation strategies.

ABA problemAtomicIntegerCAS
0 likes · 15 min read
Mastering Java CAS: How AtomicInteger Achieves Lock‑Free Concurrency
FunTester
FunTester
Jul 12, 2022 · Backend Development

Why AtomicInteger Outperforms Random() in High‑Concurrency Random Number Generation

The article analyzes two common random‑number scenarios in software testing, identifies a CPU‑heavy custom random method, benchmarks ThreadLocalRandom, AtomicInteger, and plain int implementations under multi‑ and single‑thread loads, and proposes a lightweight AtomicInteger‑based selector that consistently delivers the best performance.

AtomicIntegerPerformance TestingRandom Number Generation
0 likes · 7 min read
Why AtomicInteger Outperforms Random() in High‑Concurrency Random Number Generation
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.

AtomicIntegerCASOptimisticLocking
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.

AtomicIntegerbackend-developmentjava
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.

AtomicIntegerCyclicBarrierThreadPool
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.

AtomicIntegerCASOptimisticLocking
0 likes · 15 min read
Understanding AtomicInteger, CAS, and Lock‑Free Concurrency in Java
Java Backend Technology
Java Backend Technology
Sep 10, 2020 · Backend Development

How to Prevent Duplicate Order Numbers in High-Concurrency Java Applications

This article analyzes a real incident where duplicate order numbers were generated under high concurrency, critiques the original timestamp‑based approach, and presents a thread‑safe Java solution using AtomicInteger, Java 8 date formatting, and optional IP suffixes to ensure globally unique identifiers.

AtomicIntegerDistributed Systemsorder-number
0 likes · 9 min read
How to Prevent Duplicate Order Numbers in High-Concurrency Java Applications
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.

AtomicIntegerJMHconcurrency
0 likes · 8 min read
Testing Volatile Thread Safety and Comparing LongAdder vs AtomicInteger Performance in Java
Xiao Lou's Tech Notes
Xiao Lou's Tech Notes
Jun 18, 2020 · Backend Development

How to Build an Ultra‑Fast Ring Buffer for Producer‑Consumer in Java

This article explains a high‑performance ring buffer implementation for a multi‑threaded producer‑consumer model in Java, covering design choices, atomic index handling, benchmark results, and further optimizations such as cache‑line padding and multi‑buffer sharding.

AtomicIntegerJava concurrencyProducer Consumer
0 likes · 10 min read
How to Build an Ultra‑Fast Ring Buffer for Producer‑Consumer in Java
Programmer DD
Programmer DD
Apr 21, 2020 · Backend Development

Unlocking Java’s Unsafe: How CAS Powers High‑Performance Concurrency

This article explains Java's Unsafe class, its low‑level memory operations, how Compare‑and‑Swap (CAS) is implemented via Unsafe, and how AtomicInteger leverages CAS for lock‑free thread safety while also covering the ABA problem and its mitigation.

AtomicIntegerCASconcurrency
0 likes · 9 min read
Unlocking Java’s Unsafe: How CAS Powers High‑Performance Concurrency
FunTester
FunTester
Feb 17, 2020 · Fundamentals

Mastering Thread‑Safe Objects in Java: From Synchronized Collections to Atomic Variables

This article explains how Java threads share objects, why immutable objects are safest, how to make mutable collections thread‑safe using synchronized wrappers or concurrent classes, handles non‑thread‑safe types like SimpleDateFormat, and demonstrates race‑condition fixes with synchronized blocks and AtomicInteger.

AtomicIntegerCollectionsSynchronization
0 likes · 10 min read
Mastering Thread‑Safe Objects in Java: From Synchronized Collections to Atomic Variables
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.

AtomicIntegerjavalogin
0 likes · 8 min read
Load Testing Proportional Login Methods with Java Concurrency and AtomicInteger
JavaEdge
JavaEdge
Jan 6, 2020 · Fundamentals

Understanding Java CAS: How Compare‑And‑Swap Powers Lock‑Free Concurrency

This article explains the Compare‑And‑Swap (CAS) primitive, its three operands, how Java's Unsafe class implements CAS methods, the internal workings of AtomicInteger, common pitfalls like spinning, single‑variable limits and the ABA problem, and the enhancements introduced in Java 8.

AtomicIntegerCASJDK8
0 likes · 9 min read
Understanding Java CAS: How Compare‑And‑Swap Powers Lock‑Free Concurrency
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.

AtomicIntegerThread Locksconcurrency
0 likes · 9 min read
Understanding Java Thread Locks: synchronized, ReentrantLock, Semaphore, and AtomicInteger