Tagged articles
atomicinteger
25 articles · Page 1 of 1
This article provides a self‑test for interview preparation, presenting twelve common interview questions and detailed answers on an e‑commerce concurrency case, covering serial vs async performance, CompletableFuture.allOf, ConcurrentHashMap.compute atomicity, layered cache design, Semaphore rate limiting, ReentrantLock fairness, AtomicInteger CAS, exceptional fallback, double‑layer protection, concurrency safety testing, thread‑pool configuration, and precise cache invalidation.
CacheCompletableFutureConcurrency
0 likes · 21 min read

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.
Javaatomicintegerhigh concurrency
0 likes · 11 min read

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.
BackendConcurrencyJava
0 likes · 11 min read

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.
Javaatomicintegerthread safety
0 likes · 10 min read

This article explains five common ways to ensure thread safety in Java, covering synchronized blocks, the Lock interface, atomic variables, concurrent collections, and ThreadLocal usage, each with clear code examples and practical advice.
ConcurrencyConcurrent CollectionsJava
0 likes · 6 min read

This article explains the concept, benefits, and inner workings of CAS optimistic locks in Java, illustrating how Compare‑And‑Swap enables lock‑free synchronization and providing a practical AtomicInteger counter example to demonstrate atomic increments without traditional locking.
CASConcurrencyJava
0 likes · 4 min read

A low‑load performance test compares three ways of selecting an array index—using Math.random(), a sequential int counter, and AtomicInteger—revealing that the random‑number approach consumes significantly more CPU while AtomicInteger spikes memory usage under higher loads.
CPU usageConcurrencyJava
0 likes · 5 min read

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 problemCASUnsafe
0 likes · 15 min read

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.
ConcurrencyJavaThreadLocalRandom
0 likes · 7 min read

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.
CASJavaOptimisticLocking
0 likes · 7 min read

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.
Javaatomicintegerbackend development
0 likes · 9 min read

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.
ConcurrencyCyclicBarrierJava
0 likes · 9 min read

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.
CASConcurrencyJava
0 likes · 15 min read

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.
atomicintegerthread safetyvolatile
0 likes · 7 min read

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

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.
ConcurrencyJMHJava
0 likes · 8 min read

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.
CASConcurrencyJava
0 likes · 11 min read

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.
ABACASConcurrency
0 likes · 15 min read

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.
Java ConcurrencyProducer-Consumeratomicinteger
0 likes · 10 min read

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.
CASConcurrencyJava
0 likes · 9 min read

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.
ConcurrencyJavaSynchronization
0 likes · 10 min read

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.
Javaatomicintegerlogin
0 likes · 8 min read

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.
CASConcurrencyJDK8
0 likes · 9 min read

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.
ConcurrencyJavaSemaphore
0 likes · 9 min read

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.
CASConcurrencyJava
0 likes · 11 min read
