Tag

volatile

0 views collected around this technical thread.

Cognitive Technology Team
Cognitive Technology Team
May 2, 2025 · Backend Development

Stopping Java Threads: interrupt, volatile flag, and combined approaches

This article explains three methods for safely terminating Java threads—using the interrupt mechanism, a volatile boolean flag, and a combination of both—detailing their principles, code examples, advantages, disadvantages, and a comparative summary to guide developers in choosing the appropriate technique.

JavaThread Interruptionconcurrency
0 likes · 8 min read
Stopping Java Threads: interrupt, volatile flag, and combined approaches
Java Tech Enthusiast
Java Tech Enthusiast
Mar 4, 2025 · Backend Development

When to Use volatile with ConcurrentHashMap and Spring Bean Thread Safety

A ConcurrentHashMap is internally thread‑safe, so a volatile declaration is only required when its reference may be reassigned (or the field is final), while Spring singleton beans with mutable fields are not thread‑safe and should be made stateless, prototype‑scoped, or synchronized for composite operations.

ConcurrentHashMapJavaSpring
0 likes · 13 min read
When to Use volatile with ConcurrentHashMap and Spring Bean Thread Safety
Java Tech Enthusiast
Java Tech Enthusiast
Feb 17, 2025 · Fundamentals

Why a Java Volatile Example May Terminate Without Volatile

The program that loops on a non‑volatile boolean flag sometimes terminates because changing the counter to a volatile int or to an Integer causes the JVM to emit hidden memory barriers on reference writes, making the flag visible, but this behavior is JVM‑specific and not a reliable substitute for declaring the flag volatile.

HotSpotJVMJava
0 likes · 11 min read
Why a Java Volatile Example May Terminate Without Volatile
Sanyou's Java Diary
Sanyou's Java Diary
Sep 26, 2024 · Fundamentals

Mastering Java volatile: Visibility, Atomicity, and Memory Model Explained

This article provides a comprehensive guide to Java's volatile keyword, covering its pronunciation, core features such as visibility, lack of atomicity, and instruction reordering prevention, the Java Memory Model, cache‑coherence mechanisms, practical code examples, and best‑practice scenarios like double‑checked locking and when to prefer volatile over heavier synchronization constructs.

JMMJavaMemory Model
0 likes · 21 min read
Mastering Java volatile: Visibility, Atomicity, and Memory Model Explained
IT Services Circle
IT Services Circle
Mar 17, 2024 · Backend Development

Understanding the volatile Keyword in Java Concurrency

This article explains the Java volatile keyword, covering its underlying principles, effects on visibility and instruction reordering, appropriate usage scenarios, limitations, and provides a practical code example demonstrating how volatile ensures thread visibility and prevents dead loops in multithreaded programs.

CASJavaatomic
0 likes · 6 min read
Understanding the volatile Keyword in Java Concurrency
Cognitive Technology Team
Cognitive Technology Team
Oct 13, 2023 · Fundamentals

Understanding Java Volatile Happens‑Before Rules for Write and Read Operations

This article explains why a write to a volatile variable in Java establishes a happens‑before relationship with a subsequent read in another thread, detailing the visibility rules, ordering constraints with ordinary variables, and the transitive nature of these guarantees.

Happens-BeforeJavaMemory Model
0 likes · 3 min read
Understanding Java Volatile Happens‑Before Rules for Write and Read Operations
Top Architect
Top Architect
Aug 17, 2023 · Backend Development

Thread Communication in Java: volatile, wait/notify, CountDownLatch, ReentrantLock+Condition, and LockSupport

This article explains five Java thread‑communication techniques—volatile variables, Object.wait()/notify(), CountDownLatch, ReentrantLock with Condition, and LockSupport—providing code examples and detailed explanations of how each method works and its synchronization behavior, including sample programs that add elements to a list, demonstrate notification timing, and show how locks are acquired and released.

CountDownLatchJavaLockSupport
0 likes · 11 min read
Thread Communication in Java: volatile, wait/notify, CountDownLatch, ReentrantLock+Condition, and LockSupport
Tencent Cloud Developer
Tencent Cloud Developer
Aug 17, 2023 · Backend Development

Java Memory Model and Concurrent Programming: Visibility, Ordering, and Atomicity

The article explains how the Java Memory Model addresses concurrency challenges by defining visibility, ordering, and atomicity guarantees through mechanisms such as volatile, synchronized, cache coherence, memory barriers, CAS operations, and happens‑before relationships, enabling correct and portable multi‑threaded programming.

AtomicityCASConcurrent Programming
0 likes · 25 min read
Java Memory Model and Concurrent Programming: Visibility, Ordering, and Atomicity
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.

Double-Checked LockingJavaconcurrency
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.

Double-Checked LockingJavaconcurrency
0 likes · 6 min read
Instruction Reordering and Ordering in Java: Analysis of Double-Checked Locking
New Oriental Technology
New Oriental Technology
May 25, 2023 · Fundamentals

Deep Dive into Java volatile: CPU Cache Architecture, MESI Protocol, JMM and Happens‑Before

This article thoroughly explains the low‑level implementation of Java's volatile keyword by analysing CPU multi‑level cache design, the MESI cache‑coherency protocol, the Java Memory Model, memory barriers, the happens‑before principle, and the impact on singleton patterns and synchronized blocks.

CPU cacheHappens-BeforeJMM
0 likes · 36 min read
Deep Dive into Java volatile: CPU Cache Architecture, MESI Protocol, JMM and Happens‑Before
Mike Chen's Internet Architecture
Mike Chen's Internet Architecture
Apr 16, 2023 · Fundamentals

Understanding Java's Volatile Keyword: Memory Model, Visibility, and Implementation Details

This article explains the Java volatile keyword, covering its role in guaranteeing visibility and ordering in multithreaded environments, the underlying Java Memory Model concepts of main and working memory, the eight JMM actions, and practical implementation details with illustrative examples.

JMMJavaMemory Model
0 likes · 7 min read
Understanding Java's Volatile Keyword: Memory Model, Visibility, and Implementation Details
Selected Java Interview Questions
Selected Java Interview Questions
Mar 17, 2023 · Fundamentals

Double‑Checked Locking, Static Inner Class, and Enum Singleton Implementations in Java

This article explains three Java singleton implementations—double‑checked locking with volatile, static inner‑class holder, and enum singleton—detailing their thread‑safety, lazy initialization, and how they prevent issues such as instruction reordering, serialization, and reflection attacks.

EnumJavaconcurrency
0 likes · 14 min read
Double‑Checked Locking, Static Inner Class, and Enum Singleton Implementations in Java
Sanyou's Java Diary
Sanyou's Java Diary
Mar 16, 2023 · Fundamentals

Mastering Java’s volatile: Visibility, Atomicity, and Memory Barriers Explained

This article provides a comprehensive guide to Java's volatile keyword, covering its pronunciation, role in the Java Memory Model, visibility guarantees, lack of atomicity, instruction reordering prevention, memory barriers, and practical usage patterns such as double‑checked locking and atomic classes.

AtomicityJMMJava
0 likes · 20 min read
Mastering Java’s volatile: Visibility, Atomicity, and Memory Barriers Explained
Top Architect
Top Architect
Oct 17, 2022 · Backend Development

Understanding Java Locks: volatile, synchronized, monitor, CAS, and AQS

This article explains why locks are needed in Java, describes the fundamentals of volatile and synchronized, details the monitor‑based implementation of synchronized, introduces CAS operations, and outlines advanced lock mechanisms such as biased, lightweight, lock coarsening, elimination, and the AbstractQueuedSynchronizer framework.

AQSCASJava
0 likes · 11 min read
Understanding Java Locks: volatile, synchronized, monitor, CAS, and AQS
Selected Java Interview Questions
Selected Java Interview Questions
Jul 27, 2022 · Fundamentals

Understanding Java's volatile Keyword: CPU Cache, Memory Visibility, and the MESI Protocol

This article explains how the volatile keyword ensures visibility in Java multithreaded programs by examining CPU cache architecture, cache‑coherency mechanisms such as the MESI protocol, and the low‑level assembly effects of volatile writes on modern x86 processors.

CPU cacheJavaMESI
0 likes · 12 min read
Understanding Java's volatile Keyword: CPU Cache, Memory Visibility, and the MESI Protocol
Cognitive Technology Team
Cognitive Technology Team
May 21, 2022 · Fundamentals

Cooperative Thread Cancellation in Java: Flags and Interrupts

The article explains that Java lacks a safe preemptive way to stop threads and describes two cooperative cancellation mechanisms—using a volatile cancellation flag and using thread interruption—along with code examples and practical considerations for each approach.

CancellationInterruptJava
0 likes · 5 min read
Cooperative Thread Cancellation in Java: Flags and Interrupts
High Availability Architecture
High Availability Architecture
Mar 16, 2022 · Fundamentals

Understanding Ordering Issues and Volatile in Java Concurrency

This article explains why intuition fails in multithreaded Java programs, demonstrates ordering problems with simple thread examples, shows how instruction reordering and JIT optimizations can produce unexpected results, and presents the volatile keyword and jcstress testing as reliable solutions to ensure correct visibility and ordering.

JavaMemory Modelconcurrency
0 likes · 9 min read
Understanding Ordering Issues and Volatile in Java Concurrency