Tagged articles
12 articles
Page 1 of 1
Tech Freedom Circle
Tech Freedom Circle
Apr 25, 2026 · Fundamentals

Why a Simple Singleton Answer Failed an Alibaba Interview: The Real Role of volatile, Memory Barriers, and Happens‑Before

The article dissects an Alibaba interview question about the volatile modifier, showing why answering only with a lazy‑loaded singleton is insufficient, and explains how volatile prevents instruction reordering, establishes memory barriers, and creates happens‑before relationships to make double‑checked locking safe.

Happens-beforeJMMconcurrency
0 likes · 20 min read
Why a Simple Singleton Answer Failed an Alibaba Interview: The Real Role of volatile, Memory Barriers, and Happens‑Before
Architecture Digest
Architecture Digest
Aug 10, 2023 · Fundamentals

Instruction Reordering and Ordering in Java Double-Checked Locking

The article explains the difference between instruction reordering and ordering, analyzes how the double‑checked locking pattern can suffer from reordering at the bytecode level, and demonstrates how synchronized provides ordering while volatile only prevents visibility issues, using Java code examples and detailed bytecode analysis.

Instruction Reorderingconcurrencydouble-checked locking
0 likes · 7 min read
Instruction Reordering and Ordering in Java Double-Checked Locking
Selected Java Interview Questions
Selected Java Interview Questions
Aug 3, 2023 · Backend Development

Instruction Reordering and Ordering in Java: Analysis of Double-Checked Locking

The article explains the distinction between instruction reordering and ordering in Java, analyzes how volatile and synchronized affect memory visibility and atomicity, and demonstrates with bytecode and multithreaded examples why double‑checked locking requires both volatile and synchronized to avoid partially constructed singleton instances.

Instruction Reorderingconcurrencydouble-checked locking
0 likes · 6 min read
Instruction Reordering and Ordering in Java: Analysis of Double-Checked Locking
Selected Java Interview Questions
Selected Java Interview Questions
Feb 21, 2021 · Fundamentals

Understanding Double-Checked Locking Singleton Pattern in Java

This article explains the double-checked locking implementation of the Singleton pattern in Java, detailing why two null checks are necessary, the role of the volatile keyword in preventing instruction reordering and ensuring visibility across threads, and provides a complete example code.

Singletonconcurrencydouble-checked locking
0 likes · 5 min read
Understanding Double-Checked Locking Singleton Pattern in Java
Selected Java Interview Questions
Selected Java Interview Questions
May 9, 2020 · Fundamentals

Java Singleton Pattern: Lazy, Eager, Static Inner Class, Enum, and Double-Checked Locking

This article explains the Java Singleton pattern, covering lazy (thread‑unsafe), eager, static inner‑class, enum, and double‑checked locking implementations, discusses their thread‑safety, performance, and serialization issues, and provides complete code examples for interview preparation.

Singletondesign patterndouble-checked locking
0 likes · 6 min read
Java Singleton Pattern: Lazy, Eager, Static Inner Class, Enum, and Double-Checked Locking
FunTester
FunTester
Feb 15, 2020 · Backend Development

Understanding Double-Checked Locking Singleton Pattern in Java

This article explains the double‑checked locking design pattern for thread‑safe singletons in Java, demonstrates its performance drawbacks, and presents alternative implementations such as early initialization, init‑on‑demand holder, and enum‑based singletons, highlighting their advantages and limitations.

Singletonconcurrencydesign pattern
0 likes · 6 min read
Understanding Double-Checked Locking Singleton Pattern in Java
Programmer DD
Programmer DD
Jun 6, 2018 · Fundamentals

Why Double‑Checked Locking Fails in Java and How to Fix It

This article explains why the classic Double‑Checked Locking implementation of a lazy singleton is unsafe in Java, analyzes the underlying object‑creation reordering problem, and presents two reliable solutions—using a volatile field or a static holder class—to achieve thread‑safe lazy initialization.

Singletonconcurrencydouble-checked locking
0 likes · 7 min read
Why Double‑Checked Locking Fails in Java and How to Fix It
Programmer DD
Programmer DD
Dec 6, 2017 · Fundamentals

Mastering Java Singleton: From Lazy Initialization to Enum with Thread‑Safety

This article walks through multiple Java Singleton implementations—lazy initialization, double‑checked locking, volatile‑protected, static‑inner‑class, and enum—explaining their thread‑safety characteristics, the pitfalls of instruction reordering, and how reflection and serialization can break or preserve the pattern.

Singletondesign patterndouble-checked locking
0 likes · 10 min read
Mastering Java Singleton: From Lazy Initialization to Enum with Thread‑Safety
Java Captain
Java Captain
Nov 13, 2017 · Fundamentals

Understanding the Singleton Design Pattern in Java: Implementations, Thread Safety, and Best Practices

This article explains the Singleton design pattern in Java, covering its definition, lazy and eager implementations, thread‑safety issues such as double‑checked locking and volatile, and alternative approaches like static inner classes and enums, providing code examples and practical insights.

Singletondesign patterndouble-checked locking
0 likes · 14 min read
Understanding the Singleton Design Pattern in Java: Implementations, Thread Safety, and Best Practices