Tagged articles

Volatile

106 articles · Page 2 of 2
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.

Design PatternEnumThread Safety
0 likes · 10 min read
Mastering Java Singleton: From Lazy Initialization to Enum with Thread‑Safety
ZhiKe AI
ZhiKe AI
Feb 23, 2017 · Fundamentals

Why volatile Is Not Thread‑Safe: A Java Increment Test

The article presents a Java program where 100 threads each increment a volatile int 1,000 times, showing that the final value may be less than the expected 100,000, and explains that volatile only guarantees visibility, not atomicity, making it unsuitable for concurrent modifications.

AtomicityThread SafetyVolatile
0 likes · 2 min read
Why volatile Is Not Thread‑Safe: A Java Increment Test
Qunar Tech Salon
Qunar Tech Salon
Jul 14, 2015 · Fundamentals

Understanding Java volatile: Principles, Usage, and Best Practices

This article explains the Java volatile keyword, covering its definition, lightweight nature compared to synchronized, visibility guarantees, usage conditions, and practical patterns such as state flags, safe publication, volatile beans, and low‑cost read‑write lock strategies, illustrated with code examples.

Memory ModelVolatileconcurrency
0 likes · 9 min read
Understanding Java volatile: Principles, Usage, and Best Practices