Tag

synchronized

0 views collected around this technical thread.

Full-Stack Internet Architecture
Full-Stack Internet Architecture
May 12, 2025 · Backend Development

Why Using synchronized on a Local Variable Fails to Lock in Java Multithreading

The article demonstrates that synchronizing on a locally created object does not provide proper thread safety, shows the resulting chaotic output, and explains how moving the lock object to a class field resolves the issue, illustrated with Java code and debugging screenshots.

Javaconcurrencydebugging
0 likes · 4 min read
Why Using synchronized on a Local Variable Fails to Lock in Java Multithreading
IT Services Circle
IT Services Circle
May 10, 2025 · Backend Development

Understanding Java synchronized: Locks, Optimizations, and Example Code

This article explains how Java's synchronized keyword works, covering object and class locks, lock upgrades such as biased, lightweight, and heavyweight locks, the underlying monitor implementation, example code for a thread‑safe counter, and performance considerations for high‑concurrency scenarios.

Javaconcurrencylocking
0 likes · 7 min read
Understanding Java synchronized: Locks, Optimizations, and Example Code
Selected Java Interview Questions
Selected Java Interview Questions
Feb 18, 2025 · Backend Development

Why Java synchronized Is Insufficient in Distributed Systems and Alternative Lock Solutions

The article explains how Java's synchronized keyword works only within a single JVM, why it fails to provide mutual exclusion across multiple processes in distributed systems, and presents alternative distributed locking mechanisms such as database locks and Redis-based locks with code examples.

Distributed LockJavaRedis
0 likes · 8 min read
Why Java synchronized Is Insufficient in Distributed Systems and Alternative Lock Solutions
Architecture & Thinking
Architecture & Thinking
Jan 8, 2025 · Fundamentals

Mastering Java’s synchronized: How Object and Class Locks Control Threads

This article explains the purpose and usage of Java’s synchronized keyword, covering object locks, method locks, synchronized blocks, and class locks, along with detailed code examples that demonstrate how threads acquire and release locks to ensure data consistency in multithreaded environments.

JavaThread Safetyconcurrency
0 likes · 11 min read
Mastering Java’s synchronized: How Object and Class Locks Control Threads
FunTester
FunTester
Dec 26, 2024 · Fundamentals

Chapter 2 – Common Java Multithreading Utilities and the synchronized Keyword

This chapter introduces advanced Java multithreading concepts, explaining thread safety, the synchronized keyword, various synchronization techniques, and practical code examples such as object‑level, class‑level, method‑level synchronization and double‑checked locking to help solve concurrency problems in performance testing.

JavaSynchronizationThread Safety
0 likes · 15 min read
Chapter 2 – Common Java Multithreading Utilities and the synchronized Keyword
Mike Chen's Internet Architecture
Mike Chen's Internet Architecture
Apr 9, 2024 · Fundamentals

Deep Dive into the Underlying Implementation of Java's synchronized Keyword

This article explains the purpose, usage patterns, JVM-level object header and monitor mechanisms, lock state transitions, and lock‑upgrade strategies of Java's synchronized keyword, providing code examples and visual diagrams to illustrate how thread synchronization is achieved internally.

JVMJavaconcurrency
0 likes · 6 min read
Deep Dive into the Underlying Implementation of Java's synchronized Keyword
Full-Stack Internet Architecture
Full-Stack Internet Architecture
Nov 29, 2023 · Backend Development

Can synchronized lock a local variable? A Java multithreading demonstration

This article explains why the synchronized keyword cannot lock local variables in Java, demonstrates the behavior with multithreaded code examples, and shows that only class member variables can be effectively synchronized to control concurrent access.

Javaconcurrencylocal variable
0 likes · 4 min read
Can synchronized lock a local variable? A Java multithreading demonstration
Architecture Digest
Architecture Digest
Nov 24, 2023 · Backend Development

Eight Java synchronized Method Scenarios and Their Thread‑Safety Analysis

This article presents eight common multithreading scenarios involving Java synchronized methods, explains whether each case is thread‑safe, provides detailed code demonstrations, shows execution results, and summarizes the underlying lock mechanisms that determine safety.

JavaThread Safetyconcurrency
0 likes · 18 min read
Eight Java synchronized Method Scenarios and Their Thread‑Safety Analysis
Full-Stack Internet Architecture
Full-Stack Internet Architecture
Oct 26, 2023 · Backend Development

Differences Between Java Lock Interface and synchronized Keyword

This article explains the key differences between Java's Lock interface and the synchronized keyword, covering their nature, lock acquisition and release mechanisms, fairness, ability to query lock status, usage scenarios, and includes example code demonstrating each approach.

JavaLockThread Safety
0 likes · 5 min read
Differences Between Java Lock Interface and synchronized Keyword
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
Sanyou's Java Diary
Sanyou's Java Diary
Apr 20, 2023 · Fundamentals

Mastering Java’s synchronized: How It Works, Optimizations & Best Practices

This article explains the Java synchronized keyword, covering its purpose for thread safety, usage on methods and blocks, underlying monitor lock mechanism, JVM bytecode details, lock optimizations such as spin, bias, lightweight and heavyweight locks, and practical examples including singleton implementation and differences from volatile.

JavaThread Safetyconcurrency
0 likes · 27 min read
Mastering Java’s synchronized: How It Works, Optimizations & Best Practices
OPPO Kernel Craftsman
OPPO Kernel Craftsman
Mar 3, 2023 · Mobile Development

Understanding Java Object Locks and Their Implementation in the Android Runtime (ART)

The article explains how Java’s synchronized keyword works by describing instance, static and block locks, the monitor‑enter/exit bytecodes, the ART object header’s lock word states (thin, fat, hash, forwarding), lock inflation mechanisms, and the internal runtime functions that implement Object.wait(), notify() and related futex handling.

Android RuntimeJVMJava
0 likes · 13 min read
Understanding Java Object Locks and Their Implementation in the Android Runtime (ART)
JD Retail Technology
JD Retail Technology
Feb 21, 2023 · Fundamentals

Understanding Java Object Memory Layout, Monitor, and Synchronization Mechanisms

This article explains the JVM object memory layout—including object header, instance data, and alignment padding—details the structure of the Mark Word and Klass Word, describes how monitors and the synchronized keyword work at the bytecode level, and covers lock states, inflation, bias revocation, and spin optimizations with practical code examples.

JVMJavaLock
0 likes · 20 min read
Understanding Java Object Memory Layout, Monitor, and Synchronization Mechanisms
Rare Earth Juejin Tech Community
Rare Earth Juejin Tech Community
Nov 14, 2022 · Mobile Development

Understanding Android ART Native Implementation of synchronized: Monitor, LockWord, and Object

This article explains how the Android Runtime (ART) implements the Java synchronized keyword at the native level, detailing the roles and interactions of Monitor, LockWord, and native Object classes, as well as the thin‑lock to fat‑lock upgrade process and monitor entry/exit mechanisms.

LockWordMonitorNative
0 likes · 15 min read
Understanding Android ART Native Implementation of synchronized: Monitor, LockWord, and Object
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
Mike Chen's Internet Architecture
Mike Chen's Internet Architecture
Sep 27, 2022 · Backend Development

Four Common Ways to Implement Thread Synchronization in Java

This article explains the concept of thread synchronization in Java and provides detailed examples of four implementation methods—using the synchronized keyword, ReentrantLock, atomic variables, and ThreadLocal—along with code snippets and a comparison of their advantages and usage scenarios.

JavaReentrantLockThread Synchronization
0 likes · 6 min read
Four Common Ways to Implement Thread Synchronization in Java
Top Architect
Top Architect
Aug 26, 2022 · Backend Development

Deep Dive into Java synchronized and Lock Mechanisms: Principles, JVM Internals, and Optimizations

This article explains thread safety in Java by detailing how the synchronized keyword and various Lock implementations work, covering their underlying JVM mechanisms, lock upgrade paths, optimizations like biased and lightweight locks, and practical differences between synchronized, ReentrantLock, and ReadWriteLock.

JVMJavaLock
0 likes · 19 min read
Deep Dive into Java synchronized and Lock Mechanisms: Principles, JVM Internals, and Optimizations