Tagged articles

Thread Safety

233 articles · Page 2 of 3
Code Ape Tech Column
Code Ape Tech Column
Mar 10, 2022 · Backend Development

10 Common Pitfalls in Java Concurrency and How to Avoid Them

This article outlines ten typical concurrency pitfalls in Java—including SimpleDateFormat thread‑safety, double‑checked locking flaws, volatile atomicity limits, deadlocks, lock release issues, HashMap race conditions, default thread‑pool misuse, @Async thread explosion, spin‑lock CPU waste, and ThreadLocal memory leaks—providing explanations, code examples, and practical solutions for each.

SpringThread Safetyconcurrency
0 likes · 20 min read
10 Common Pitfalls in Java Concurrency and How to Avoid Them
IT Services Circle
IT Services Circle
Mar 7, 2022 · Backend Development

10 Common Java Concurrency Pitfalls and How to Avoid Them

This article outlines ten frequent Java concurrency pitfalls—including unsafe SimpleDateFormat usage, double‑checked locking flaws, volatile limitations, deadlocks, HashMap memory leaks, thread‑pool misuse, @Async traps, spin‑lock inefficiencies, and ThreadLocal memory leaks—providing explanations, code examples, and practical solutions for each.

Thread Safetybest practicesconcurrency
0 likes · 21 min read
10 Common Java Concurrency Pitfalls and How to Avoid Them
Spring Full-Stack Practical Cases
Spring Full-Stack Practical Cases
Feb 7, 2022 · Backend Development

Why MyBatis SqlSession Fails with Multiple Threads and How Spring Guarantees Thread Safety

An in‑depth guide shows how running 100 concurrent MyBatis queries triggers a ClassCastException, explains the underlying cache placeholder issue, and demonstrates how Spring Boot’s SqlSessionTemplate and transaction management guarantee thread‑safe SqlSession usage through ThreadLocal binding.

MyBatisORMSpring Boot
0 likes · 19 min read
Why MyBatis SqlSession Fails with Multiple Threads and How Spring Guarantees Thread Safety
Zhuanzhuan Tech
Zhuanzhuan Tech
Jan 26, 2022 · Fundamentals

Understanding the Happens‑Before Principle in Java Concurrency

This article explains the Java Happens‑Before principle, detailing its rules such as program order, monitor lock, volatile variable, thread start, termination, interruption, and finalizer, and demonstrates each rule with clear code examples to illustrate visibility guarantees in concurrent programming.

Memory ModelThread Safetyhappens-before
0 likes · 28 min read
Understanding the Happens‑Before Principle in Java Concurrency
Java Interview Crash Guide
Java Interview Crash Guide
Jan 14, 2022 · Fundamentals

How Does Java’s ThreadLocal Avoid Memory Leaks? Deep Dive into Its Design

This article explores Java's thread‑local storage, explaining why shared variables cause thread‑safety issues, how a proxy can hide object retrieval, the pitfalls of a naive Map‑based design that leads to memory leaks, and how the JDK's ThreadLocal uses weak references and ThreadLocalMap to safely manage per‑thread data.

Thread SafetyThreadLocaljava
0 likes · 8 min read
How Does Java’s ThreadLocal Avoid Memory Leaks? Deep Dive into Its Design
DeWu Technology
DeWu Technology
Dec 26, 2021 · Fundamentals

Java Synchronized Mechanism Overview

Java's synchronized keyword provides mutual exclusion by using object monitors, offering class‑method, static‑method, and block locking patterns, while the JVM optimizes performance through biased, lightweight, and heavyweight lock strategies, making it essential knowledge for efficient concurrent programming.

JVMThread Safetyconcurrency
0 likes · 29 min read
Java Synchronized Mechanism Overview
Selected Java Interview Questions
Selected Java Interview Questions
Nov 29, 2021 · Backend Development

Understanding Synchronized and Concurrent Containers in Java

The article explains Java's synchronized containers such as Vector, Stack, and Hashtable, demonstrates their usage and pitfalls, then introduces concurrent containers like ConcurrentHashMap, CopyOnWriteArrayList, and ConcurrentSkipListSet, providing code examples and best practices for thread‑safe collection handling.

Collections FrameworkConcurrent ContainersSynchronized Collections
0 likes · 17 min read
Understanding Synchronized and Concurrent Containers in Java
Java Tech Enthusiast
Java Tech Enthusiast
Nov 18, 2021 · Fundamentals

Pessimistic and Optimistic Locks in Java: Theory and Code Examples

The article compares Java's pessimistic locking mechanisms such as synchronized blocks and ReentrantLock with optimistic approaches like version checks, CAS‑based AtomicInteger and custom spin locks, illustrating each method through counter examples and discussing their performance trade‑offs and limitations.

CASLocksThread Safety
0 likes · 11 min read
Pessimistic and Optimistic Locks in Java: Theory and Code Examples
FunTester
FunTester
Nov 5, 2021 · Backend Development

Master Java ReentrantLock: Simple Thread‑Safe Coding Without synchronized

This article introduces Java's ReentrantLock as an easy-to‑use alternative to synchronized, explains its core lock() and unlock() methods, demonstrates practical code examples, and covers advanced APIs such as tryLock, getQueueLength, isLocked, and getHoldCount for robust multithreaded programming.

ReentrantLockThread Safetybackend
0 likes · 5 min read
Master Java ReentrantLock: Simple Thread‑Safe Coding Without synchronized
360 Zhihui Cloud Developer
360 Zhihui Cloud Developer
Oct 21, 2021 · Backend Development

Mastering sync.Once in Go: Thread‑Safe Singleton Patterns Explained

This article explains Go's sync.Once primitive, compares it with init, details various singleton implementations—including lazy, eager, and double‑checked locking—and provides practical code examples and a deep dive into its source implementation for thread‑safe one‑time initialization.

GoLazy InitializationThread Safety
0 likes · 7 min read
Mastering sync.Once in Go: Thread‑Safe Singleton Patterns Explained
Wukong Talks Architecture
Wukong Talks Architecture
Oct 18, 2021 · Fundamentals

Understanding Thread Safety Issues in Java Collections: ArrayList, HashSet, and HashMap

This article explains the thread‑unsafe nature of Java’s ArrayList, HashSet and HashMap, details their internal implementations and growth mechanisms, and presents three common solutions—Vector, synchronized wrappers, and CopyOnWrite collections—to achieve thread safety in concurrent environments.

CollectionsThread Safetyarraylist
0 likes · 15 min read
Understanding Thread Safety Issues in Java Collections: ArrayList, HashSet, and HashMap
Java Interview Crash Guide
Java Interview Crash Guide
Oct 18, 2021 · Backend Development

Why Thread Safety Fails in Java and How to Ensure It

This article explains how variable sharing in multithreaded Java programs leads to thread‑unsafe behavior, explores the JVM memory model and stack frame structure, and demonstrates practical ways to achieve thread safety by keeping variables thread‑local or using proxy objects.

JVMThread Safetyconcurrency
0 likes · 10 min read
Why Thread Safety Fails in Java and How to Ensure It
Python Programming Learning Circle
Python Programming Learning Circle
Oct 7, 2021 · Fundamentals

Thread‑Safe Counter Implementations in Python: Single‑Thread, Fast‑Read, and Fast‑Write Approaches

This article explains how to implement simple counters in Python, demonstrates why a naïve single‑thread counter is not safe for concurrent use, and presents three thread‑safe alternatives—using a lock, leveraging the GIL with itertools.count, and a combined fast‑read/fast‑write design—along with a performance comparison.

GILThread Safety
0 likes · 8 min read
Thread‑Safe Counter Implementations in Python: Single‑Thread, Fast‑Read, and Fast‑Write Approaches
Programmer DD
Programmer DD
Sep 26, 2021 · Backend Development

Mastering ThreadLocal in Java: When and How to Use It Safely

This article explains the two primary use cases of ThreadLocal in Java—providing each thread with its own exclusive object and sharing request‑scoped data across methods—while covering implementation details, memory‑leak risks, and best‑practice cleanup techniques.

Thread SafetyThreadLocalbackend development
0 likes · 10 min read
Mastering ThreadLocal in Java: When and How to Use It Safely
Programmer DD
Programmer DD
Sep 14, 2021 · Backend Development

Why Spring MVC Controllers Are Singleton and How to Ensure Thread Safety

This article explains that Spring MVC controllers are singleton by default, illustrates the thread‑safety problems caused by shared instance variables with concrete code examples, and provides practical solutions such as avoiding state, using prototype scope, ThreadLocal, or AtomicInteger to make controllers safe under high concurrency.

ControllerThread Safetyconcurrency
0 likes · 6 min read
Why Spring MVC Controllers Are Singleton and How to Ensure Thread Safety
Selected Java Interview Questions
Selected Java Interview Questions
Sep 12, 2021 · Backend Development

Understanding Java ConcurrentHashMap: Initialization, Null Handling, Resizing, Data Structure, Operations, and Thread‑Safety

This article explains Java 1.8 ConcurrentHashMap’s default capacity, null‑key/value restrictions, resizing behavior, internal array‑list‑tree structure, node fields, put and get processes, thread‑safety mechanisms, iterator consistency, and differences between JDK 7 and JDK 8 implementations.

ConcurrentHashMapJava 8Thread Safety
0 likes · 9 min read
Understanding Java ConcurrentHashMap: Initialization, Null Handling, Resizing, Data Structure, Operations, and Thread‑Safety
ITPUB
ITPUB
Jul 29, 2021 · Fundamentals

Mastering Java’s Happens‑Before Principle and Memory Model

This article explains the Java Memory Model, how threads interact with main and working memory, and details the happens‑before rules—including program order, monitor, volatile, thread start, join, and transfer—to help developers understand visibility and ordering challenges in concurrent Java programs.

Memory ModelThread Safetyhappens-before
0 likes · 10 min read
Mastering Java’s Happens‑Before Principle and Memory Model
Programmer DD
Programmer DD
Jun 17, 2021 · Backend Development

Why StringBuilder Fails in Multithreaded Code and How StringBuffer Solves It

This article explains why StringBuilder is not thread‑safe, demonstrates the problem with a multithreaded example that produces a wrong length and occasional ArrayIndexOutOfBoundsException, and shows how StringBuffer’s synchronized implementation avoids these issues.

StringBufferStringBuilderThread Safety
0 likes · 8 min read
Why StringBuilder Fails in Multithreaded Code and How StringBuffer Solves It
New Oriental Technology
New Oriental Technology
May 31, 2021 · Backend Development

A Comprehensive Guide to Java Concurrency and Synchronization Mechanisms

This article provides an in-depth exploration of Java concurrency and synchronization mechanisms, detailing the evolution of the Java Memory Model, explaining core concepts like volatile, CAS, synchronized, and park/unpark, and illustrating their practical applications through code examples and JVM optimization insights.

CASJVM OptimizationJava concurrency
0 likes · 15 min read
A Comprehensive Guide to Java Concurrency and Synchronization Mechanisms
Full-Stack Internet Architecture
Full-Stack Internet Architecture
May 18, 2021 · Backend Development

Understanding Thread Safety Issues with SimpleDateFormat and Solutions in Java

This article explains why SimpleDateFormat is not thread‑safe in Java, demonstrates the problem with multithreaded examples, and presents five practical solutions—including local variables, synchronized blocks, explicit locks, ThreadLocal, and the modern DateTimeFormatter—along with their advantages and drawbacks.

DateTimeFormatterSimpleDateFormatThread Safety
0 likes · 13 min read
Understanding Thread Safety Issues with SimpleDateFormat and Solutions in Java
Full-Stack Internet Architecture
Full-Stack Internet Architecture
May 15, 2021 · Backend Development

Using ThreadLocal in Java: Scenarios, Thread‑Safety Problems, and Practical Solutions

This article explains why ThreadLocal is both simple and tricky to use, demonstrates common pitfalls when formatting dates with SimpleDateFormat in multithreaded environments, analyzes thread‑safety issues, and provides practical solutions using synchronized blocks, ThreadLocal, and its advanced initialization methods for clean and efficient concurrent code.

Thread PoolThread SafetyThreadLocal
0 likes · 20 min read
Using ThreadLocal in Java: Scenarios, Thread‑Safety Problems, and Practical Solutions
FunTester
FunTester
May 6, 2021 · Backend Development

Do Thread‑Safe Classes and synchronized Really Slow Down Performance Tests?

This article examines how adding Java thread‑safe classes and the synchronized keyword influences QPS in performance testing, presenting code modifications, benchmark results for 20 and 40 threads, and concluding that their impact on measured throughput is minimal.

Performance TestingQPSThread Safety
0 likes · 8 min read
Do Thread‑Safe Classes and synchronized Really Slow Down Performance Tests?
TAL Education Technology
TAL Education Technology
Apr 8, 2021 · Backend Development

Java Concurrency Programming: Concepts, Tools, and Practical Examples

This comprehensive guide introduces Java concurrency fundamentals, explains common tools and their underlying principles, discusses typical challenges such as thread safety, visibility, and ordering, and provides practical code examples and optimization techniques for building high‑performance multithreaded applications.

Thread Safetyconcurrencyjava
0 likes · 16 min read
Java Concurrency Programming: Concepts, Tools, and Practical Examples
Selected Java Interview Questions
Selected Java Interview Questions
Apr 5, 2021 · Backend Development

Understanding Thread Safety in Java: StringBuilder, StringBuffer, and Servlets

This article explains the thread‑safety differences between StringBuilder and StringBuffer, demonstrates the problems of using mutable shared objects in multithreaded Java code, presents three solutions, and discusses why Servlets are not thread‑safe by default, highlighting visibility and ordering concepts.

ServletStringBufferStringBuilder
0 likes · 10 min read
Understanding Thread Safety in Java: StringBuilder, StringBuffer, and Servlets
Intelligent Backend & Architecture
Intelligent Backend & Architecture
Apr 2, 2021 · Fundamentals

Master Java Collections: From ArrayList to ConcurrentHashMap Explained

This article provides a comprehensive overview of Java's collection framework, detailing the roles of interfaces, implementations, and algorithms, comparing collections with arrays, describing common List, Set, and Map classes, their underlying data structures, thread‑safety characteristics, and best practices for iteration and usage.

CollectionsConcurrentHashMapData Structures
0 likes · 48 min read
Master Java Collections: From ArrayList to ConcurrentHashMap Explained
FunTester
FunTester
Mar 2, 2021 · Operations

How to Diversify Request Parameters for Robust Performance Testing

This article explains practical techniques for generating varied request parameters—such as random numbers, thread‑safe identifiers, random strings, and upstream data extraction—to avoid identical inputs in multi‑call performance tests and improve test reliability.

AutomationPerformance TestingThread Safety
0 likes · 12 min read
How to Diversify Request Parameters for Robust Performance Testing
Full-Stack Internet Architecture
Full-Stack Internet Architecture
Feb 18, 2021 · Fundamentals

Comprehensive Guide to the Singleton Pattern in Java: Implementations, Pitfalls, and the Secure Enum Solution

This article explains various Java singleton implementations—including eager, lazy, double‑checked locking, static inner class, and enum—demonstrates their thread‑safety issues, shows how reflection and serialization can break them, and presents the enum approach as a truly safe solution.

Design PatternEnumThread Safety
0 likes · 11 min read
Comprehensive Guide to the Singleton Pattern in Java: Implementations, Pitfalls, and the Secure Enum Solution
Top Architect
Top Architect
Feb 10, 2021 · Backend Development

Understanding Thread Safety Issues in Java ArrayList and How to Fix Them

This article explains why Java's ArrayList is not thread‑safe, illustrates the two main concurrency problems—array index out‑of‑bounds and element overwriting—through source‑code analysis and multithreaded examples, and presents several practical solutions such as synchronized wrappers, explicit locking, CopyOnWriteArrayList and ThreadLocal.

CollectionsCopyOnWriteArrayListThread Safety
0 likes · 11 min read
Understanding Thread Safety Issues in Java ArrayList and How to Fix Them
FunTester
FunTester
Feb 6, 2021 · Fundamentals

Mastering Java ThreadLocal: Achieve Thread‑Safe Objects Without synchronized

This article explains how Java's ThreadLocal class provides a thread‑local storage mechanism that creates independent object instances for each thread, improving scalability and performance compared to synchronized blocks, and demonstrates its usage with practical code examples and best‑practice guidelines.

Thread SafetyThreadLocalbackend development
0 likes · 8 min read
Mastering Java ThreadLocal: Achieve Thread‑Safe Objects Without synchronized
FunTester
FunTester
Jan 15, 2021 · Operations

Customizing Request Marking for Java API Performance Testing

This article explains how to modify a Java search API and write custom performance‑testing scripts that embed unique request marks, enabling precise measurement of each request's response time when header‑based marking is unavailable.

APIScriptingThread Safety
0 likes · 6 min read
Customizing Request Marking for Java API Performance Testing
Su San Talks Tech
Su San Talks Tech
Dec 8, 2020 · Backend Development

How Java's ConcurrentHashMap Delivers High‑Performance Thread Safety

This article explains the internal design of Java's ConcurrentHashMap, covering its evolution from JDK7 to JDK8, the segment‑based locking mechanism, lock‑free reads, CAS operations, table resizing, treeification, and the key classes and methods that enable efficient concurrent access while maintaining thread safety.

CASConcurrentHashMapLock Splitting
0 likes · 42 min read
How Java's ConcurrentHashMap Delivers High‑Performance Thread Safety
Top Architect
Top Architect
Dec 8, 2020 · Backend Development

Understanding Thread Safety of Spring Beans: Singleton vs Prototype Scope

This article explains why Spring beans are not inherently thread‑safe, compares the singleton and prototype scopes, shows how stateless beans can be safe, demonstrates the impact of static fields and injected beans, and provides practical code examples and recommendations for achieving thread safety in Spring applications.

BeanScopeSpring
0 likes · 11 min read
Understanding Thread Safety of Spring Beans: Singleton vs Prototype Scope
ITPUB
ITPUB
Dec 2, 2020 · Backend Development

Why Thread Safety and Reentrancy Matter in C++ Backend Development

The article uses a casual conversation between two backend engineers to introduce multithreading concepts, explain shared vs. private resources, define thread‑safe and reentrant functions, illustrate common pitfalls with code examples, and provide practical guidelines for writing correct concurrent C++ services.

C++ReentrancyThread Safety
0 likes · 11 min read
Why Thread Safety and Reentrancy Matter in C++ Backend Development
Architecture Digest
Architecture Digest
Nov 8, 2020 · Backend Development

Key Considerations and Implementation Strategies for a Local Cache in Java

This article outlines the essential design considerations for building a local cache—such as data structures, size limits, eviction policies, expiration, thread safety, simple APIs, persistence, and blocking mechanisms—and demonstrates concrete Java implementations with code examples.

MyBatisThread Safetyeviction policy
0 likes · 11 min read
Key Considerations and Implementation Strategies for a Local Cache in Java
Full-Stack Internet Architecture
Full-Stack Internet Architecture
Oct 14, 2020 · Fundamentals

Singleton Pattern – Ensuring a Unique Instance in Java

This article explains the definition, class diagram, and multiple Java implementations of the Singleton pattern—including eager, lazy, double‑checked locking, static inner class, and enum approaches—while discussing thread safety, volatile usage, and practical considerations.

Design PatternEnumLazy Initialization
0 likes · 9 min read
Singleton Pattern – Ensuring a Unique Instance in Java
Su San Talks Tech
Su San Talks Tech
Oct 7, 2020 · Backend Development

8 Proven Java Techniques to Ensure Thread‑Safe Data in Concurrent Apps

This article outlines eight practical Java approaches—including stateless design, immutability, safe publication, volatile fields, synchronized blocks, explicit locks, CAS operations, and ThreadLocal—to guarantee data safety in multithreaded environments, explaining each concept and providing concise code examples.

CASLockThread Safety
0 likes · 6 min read
8 Proven Java Techniques to Ensure Thread‑Safe Data in Concurrent Apps
vivo Internet Technology
vivo Internet Technology
Sep 16, 2020 · Backend Development

How ConcurrentHashMap Guarantees Thread‑Safe Reads and Writes: A Deep Dive into C13Map Internals

This article explains the fundamentals of HashMap, then dissects the internal fields, node‑array safety, read‑path guarantees, write‑path locking, atomic compute methods, resize‑transfer mechanics, traverser design, and bulk‑task support that together make Java's ConcurrentHashMap (C13Map) a highly concurrent, lock‑free data structure.

ConcurrentHashMapData StructuresHashMap
0 likes · 49 min read
How ConcurrentHashMap Guarantees Thread‑Safe Reads and Writes: A Deep Dive into C13Map Internals
Senior Brother's Insights
Senior Brother's Insights
Sep 15, 2020 · Fundamentals

Why Is StringBuilder Not Thread‑Safe? Deep Dive into Java’s Internals

Although StringBuilder and StringBuffer share similar APIs, StringBuilder lacks thread safety because its append method updates shared fields without synchronization, leading to race conditions that can corrupt the internal char array and cause ArrayIndexOutOfBoundsException, as demonstrated by a multithreaded test example.

JVMStringBuilderThread Safety
0 likes · 7 min read
Why Is StringBuilder Not Thread‑Safe? Deep Dive into Java’s Internals
Wukong Talks Architecture
Wukong Talks Architecture
Aug 31, 2020 · Fundamentals

Understanding Thread Safety Issues in Java Collections: ArrayList, HashSet, HashMap and Their Solutions

This article explains why core Java collection classes such as ArrayList, HashSet, and HashMap are not thread‑safe, demonstrates the underlying mechanisms of their initialization and resizing, and presents multiple approaches—including Vector, synchronized wrappers, and CopyOnWrite variants—to achieve safe concurrent access.

HashMapHashSetThread Safety
0 likes · 16 min read
Understanding Thread Safety Issues in Java Collections: ArrayList, HashSet, HashMap and Their Solutions
Java Backend Technology
Java Backend Technology
Aug 18, 2020 · Backend Development

Why Spring Controllers Are Not Thread‑Safe and How to Fix Them

Spring MVC controllers are singleton by default, which can cause thread‑unsafe behavior when using non‑static member variables; this article demonstrates the issue with example endpoints, shows how prototype scope resolves it, and outlines best practices such as avoiding stateful fields or using ThreadLocal.

Bean ScopeControllerSpring
0 likes · 5 min read
Why Spring Controllers Are Not Thread‑Safe and How to Fix Them
Top Architect
Top Architect
Aug 6, 2020 · Backend Development

Understanding Spring Controller Bean Scope: Singleton vs Prototype and Thread Safety

This article explains why Spring MVC controllers are singleton by default, demonstrates the thread‑safety issues caused by shared instance variables, shows how to test the behavior with sample code, and presents solutions such as using prototype scope, avoiding member variables, or employing ThreadLocal.

Bean ScopeControllerSpring
0 likes · 6 min read
Understanding Spring Controller Bean Scope: Singleton vs Prototype and Thread Safety
macrozheng
macrozheng
Aug 6, 2020 · Backend Development

When ‘No‑Comment’ Java Code Triggers a Memory Leak – A ConcurrentHashMap Study

A newly hired architect boasts high‑concurrency expertise but writes un‑commented Java code that misuses ConcurrentHashMap, leading to memory leaks; the ensuing investigation reveals missing equals/hashCode implementations, race conditions in a visit method, and a debate between synchronized blocks and putIfAbsent for safe updates.

ConcurrentHashMapThread Safetybackend development
0 likes · 8 min read
When ‘No‑Comment’ Java Code Triggers a Memory Leak – A ConcurrentHashMap Study
Selected Java Interview Questions
Selected Java Interview Questions
Jul 27, 2020 · Backend Development

Understanding Spring Controller Scope and Thread Safety

The article explains why Spring MVC controllers are singleton by default, demonstrates the resulting thread‑unsafe behavior with example code, shows how applying @Scope("prototype") makes them prototype scoped, and provides best‑practice recommendations and a summary of Spring bean scopes.

BeanControllerScope
0 likes · 5 min read
Understanding Spring Controller Scope and Thread Safety
FunTester
FunTester
Jul 19, 2020 · Operations

How to Build a Thread‑Safe Global Counter in JMeter with Groovy

This guide explains how to create a globally unique, auto‑incrementing variable in JMeter by using a synchronized Groovy script that leverages the built‑in props object, demonstrates setting an initial value, and compares locked versus unlocked execution results.

Global VariableGroovyJMeter
0 likes · 8 min read
How to Build a Thread‑Safe Global Counter in JMeter with Groovy
Programmer DD
Programmer DD
Jun 29, 2020 · Backend Development

Why Spring Beans Aren’t Thread‑Safe and How ThreadLocal Solves It

This article explains that Spring does not guarantee thread safety for its beans, describes the various bean scopes, clarifies why stateless singleton beans are safe, and shows how ThreadLocal works—including its implementation, usage, and potential memory‑leak pitfalls—so developers can write correct concurrent code.

SpringThread SafetyThreadLocal
0 likes · 17 min read
Why Spring Beans Aren’t Thread‑Safe and How ThreadLocal Solves It
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.

Design PatternEnumLazy Initialization
0 likes · 6 min read
Java Singleton Pattern: Lazy, Eager, Static Inner Class, Enum, and Double-Checked Locking
Full-Stack Internet Architecture
Full-Stack Internet Architecture
Apr 26, 2020 · Fundamentals

Understanding ConcurrentHashMap: Implementation Differences between JDK 1.7 and JDK 1.8

This article explains why ConcurrentHashMap provides thread‑safe and high‑performance map operations, compares it with HashMap and Hashtable, and details the architectural changes from JDK 1.7’s segment‑lock design to JDK 1.8’s array‑list‑red‑black‑tree and CAS‑based implementation.

ConcurrentHashMapData StructuresJDK7
0 likes · 7 min read
Understanding ConcurrentHashMap: Implementation Differences between JDK 1.7 and JDK 1.8
Sohu Tech Products
Sohu Tech Products
Apr 22, 2020 · Backend Development

Understanding ThreadLocal in Java: Implementation, Memory‑Leak Risks, and Practical Use Cases

This article explains Java's ThreadLocal mechanism, shows how it provides thread‑confinement without synchronization, analyses its source code—including hash generation, internal ThreadLocalMap structure, set/get operations and resize logic—highlights potential memory‑leak pitfalls, and lists common application scenarios.

Thread SafetyThreadLocalbackend development
0 likes · 16 min read
Understanding ThreadLocal in Java: Implementation, Memory‑Leak Risks, and Practical Use Cases
Watermelon Video Tech Team
Watermelon Video Tech Team
Apr 7, 2020 · Mobile Development

Investigation and Fix of Android Native Crash in CookieManager.getCookie Caused by Thread‑Unsafe GURL Initialization

An in‑depth analysis of a long‑standing native crash on Android caused by thread‑unsafe initialization of GURL during CookieManager.getCookie calls, detailing stack traces, investigation steps, source code examination, and a lightweight application‑level synchronization fix that eliminated the issue in production.

AndroidCookieManagerGURL
0 likes · 10 min read
Investigation and Fix of Android Native Crash in CookieManager.getCookie Caused by Thread‑Unsafe GURL Initialization
Java Captain
Java Captain
Mar 28, 2020 · Fundamentals

Understanding the Impact of Print Statements, sleep, and Integer on Java Thread Safety

This article explores how adding print statements, using Thread.sleep, and employing Integer objects affect thread safety in Java, illustrating why a non‑volatile flag can cause infinite loops, how synchronized I/O and sleep influence memory visibility, and why seemingly unrelated changes sometimes make the program terminate.

Thread Safetyjavajit
0 likes · 15 min read
Understanding the Impact of Print Statements, sleep, and Integer on Java Thread Safety
Architecture Digest
Architecture Digest
Mar 14, 2020 · Fundamentals

Understanding the Java Memory Model (JMM) and Its Concurrency Rules

This article explains the Java Memory Model, describing how main memory and thread‑local working memory interact, the eight primitive actions defined by the JVM, the special semantics of volatile, long and double variables, and how these concepts underpin atomicity, visibility and the happens‑before principle in concurrent Java programs.

Memory ModelThread SafetyVolatile
0 likes · 23 min read
Understanding the Java Memory Model (JMM) and Its Concurrency Rules
FunTester
FunTester
Feb 26, 2020 · Fundamentals

Why Thread‑Safe Collections Still Fail with Non‑Thread‑Safe Objects in Java

Through a series of Java demos, this article examines how storing non‑thread‑safe objects inside thread‑safe collections like ConcurrentHashMap or CopyOnWriteArrayList can still cause concurrency bugs, explains the underlying remove() implementation, and shows how switching to a thread‑safe Vector resolves the issue.

CollectionsConcurrentHashMapCopyOnWriteArrayList
0 likes · 8 min read
Why Thread‑Safe Collections Still Fail with Non‑Thread‑Safe Objects in Java
FunTester
FunTester
Feb 24, 2020 · Backend Development

Achieving Thread‑Safe Java Performance Tests Without Locks

This article explains why traditional locking harms Java performance‑testing throughput, introduces lock‑free alternatives such as CAS and ThreadLocal, and provides a complete Java demo that shows how each thread can hold its own object to eliminate contention and boost speed.

Lock-FreePerformance TestingThread Safety
0 likes · 5 min read
Achieving Thread‑Safe Java Performance Tests Without Locks
FunTester
FunTester
Feb 17, 2020 · Fundamentals

Mastering Thread‑Safe Objects in Java: From Synchronized Collections to Atomic Variables

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.

AtomicIntegerCollectionsThread Safety
0 likes · 10 min read
Mastering Thread‑Safe Objects in Java: From Synchronized Collections to Atomic Variables
Architect's Tech Stack
Architect's Tech Stack
Feb 14, 2020 · Backend Development

Understanding ThreadLocal Variables in Java: Implementation, Memory Leak Issues, and Use Cases

This article explains what ThreadLocal variables are, how they are implemented in Java using a per‑thread ThreadLocalMap, discusses potential memory‑leak pitfalls caused by weak keys, and demonstrates common usage scenarios such as per‑thread session storage and making non‑thread‑safe classes like SimpleDateFormat thread‑safe.

Thread SafetyThreadLocalmemory leak
0 likes · 7 min read
Understanding ThreadLocal Variables in Java: Implementation, Memory Leak Issues, and Use Cases
FunTester
FunTester
Jan 26, 2020 · Backend Development

Common Concurrency Bugs in Backend Java Development and Their Solutions

Although developers often overlook high‑concurrency scenarios, this article highlights two typical backend Java concurrency bugs—shared request state in singleton beans and improper lazy initialization—explains their pitfalls, and demonstrates correct thread‑safe patterns such as double‑checked locking and proper singleton design.

Lazy InitializationThread Safetyconcurrency
0 likes · 5 min read
Common Concurrency Bugs in Backend Java Development and Their Solutions
Architecture Digest
Architecture Digest
Jan 4, 2020 · Backend Development

Java Concurrency: Thread Safety, Visibility, Atomicity, and Lock Mechanisms

This article provides a comprehensive overview of Java concurrency concepts, covering thread‑safety issues, variable visibility, atomic operations, the use of synchronized, volatile, ReentrantLock, ReadWriteLock, CountDownLatch, and other AQS‑based synchronizers, with code examples illustrating each mechanism.

AQSLocksThread Safety
0 likes · 34 min read
Java Concurrency: Thread Safety, Visibility, Atomicity, and Lock Mechanisms
Senior Brother's Insights
Senior Brother's Insights
Nov 4, 2019 · Fundamentals

Why Understanding Java Memory Model Boosts Your Code Efficiency

This article explains the hardware memory architecture, the role of caches, and how the Java Memory Model abstracts thread interaction with main and working memory, detailing the eight fundamental JMM operations, their ordering rules, and special considerations for long and double types to help developers write correct, high‑performance concurrent Java code.

JVMMemory ModelThread Safety
0 likes · 11 min read
Why Understanding Java Memory Model Boosts Your Code Efficiency
Java Architecture Diary
Java Architecture Diary
Nov 2, 2019 · Backend Development

Why SimpleDateFormat Is Not Thread‑Safe and How to Fix It Efficiently

This article explains why Java's SimpleDateFormat is not thread‑safe, demonstrates the resulting concurrency errors, and presents four practical solutions—including per‑call instantiation, ThreadLocal, Apache FastDateFormat, and Java 8's Instant with DateTimeFormatter—along with JMH benchmark results comparing their performance across JDK 8 and JDK 11.

SimpleDateFormatThread SafetyThreadLocal
0 likes · 7 min read
Why SimpleDateFormat Is Not Thread‑Safe and How to Fix It Efficiently
FunTester
FunTester
Oct 27, 2019 · Operations

How to Load Test Multi‑Row Single Updates with Thread‑Safe Queues in Java

This article explains how to perform load testing for scenarios where each row can be updated only once, using a thread‑safe queue to supply unique parameters to concurrent threads, and provides complete Java code examples for both a global queue and per‑thread queues.

Load TestingPerformance TestingQueue
0 likes · 6 min read
How to Load Test Multi‑Row Single Updates with Thread‑Safe Queues in Java
Selected Java Interview Questions
Selected Java Interview Questions
Oct 20, 2019 · Fundamentals

Java Singleton Pattern Implementations and Variants

This article explains four main categories of Java singleton implementations—eager (hungry), lazy (lazy), holder, and enum—detailing their basic forms, variations, thread‑safety characteristics, performance trade‑offs, and code examples, while also discussing pitfalls such as reflection and serialization.

Design PatternEnumLazy Initialization
0 likes · 10 min read
Java Singleton Pattern Implementations and Variants
Programmer DD
Programmer DD
Sep 5, 2019 · Fundamentals

Understanding ThreadLocal: Solving Thread Safety Issues in Java

This article explains thread safety problems, demonstrates how unsynchronized access to shared variables can produce incorrect results, and shows how Java's ThreadLocal and InheritableThreadLocal classes provide thread‑local storage to avoid concurrency bugs, including implementation details and usage examples.

InheritableThreadLocalThread SafetyThreadLocal
0 likes · 9 min read
Understanding ThreadLocal: Solving Thread Safety Issues in Java
Programmer DD
Programmer DD
Aug 24, 2019 · Fundamentals

Why Java Strings Are Immutable and How It Boosts Performance

This article explains the concept of Java String immutability, illustrates how references work with examples and diagrams, and discusses the benefits such as string pool reuse, hashcode caching, thread safety, and security that improve memory efficiency and application performance.

ImmutabilityThread Safetyjava
0 likes · 8 min read
Why Java Strings Are Immutable and How It Boosts Performance
FunTester
FunTester
Jul 22, 2019 · Fundamentals

Why i++ Is Not Thread‑Safe: A Hands‑On Demo with vmlens

This article demonstrates how the non‑atomic i++ operation can cause race conditions in Java by using the vmlens tool to visualize thread interleavings, providing sample test code, Maven configuration, and an analysis of the resulting report.

Thread Safetyconcurrencyjava
0 likes · 6 min read
Why i++ Is Not Thread‑Safe: A Hands‑On Demo with vmlens
FunTester
FunTester
Jul 22, 2019 · Backend Development

Thread Safety Issues When Combining Thread‑Safe Methods: A ConcurrentHashMap Example

Even when using thread‑safe classes like Java's ConcurrentHashMap, combining multiple thread‑safe methods into a single operation can still cause race conditions, as demonstrated by a test where two threads concurrently execute get‑and‑put logic, leading to an unexpected map value and a failed assertion.

ConcurrentHashMapThread Safetyconcurrency
0 likes · 3 min read
Thread Safety Issues When Combining Thread‑Safe Methods: A ConcurrentHashMap Example
FunTester
FunTester
Jul 19, 2019 · Fundamentals

Why i++ Is Not Thread‑Safe: A Hands‑On Demo with vmlens

This article demonstrates how the non‑atomic i++ operation can cause race conditions in Java, using a simple multithreaded test and the vmlens tool to visualize the conflicting accesses and explain the underlying thread‑safety issue.

MavenThread Safetyjava
0 likes · 7 min read
Why i++ Is Not Thread‑Safe: A Hands‑On Demo with vmlens
FunTester
FunTester
Jul 16, 2019 · Fundamentals

Why Incrementing a Counter Isn’t Thread‑Safe in Java: A Hands‑On Demo

This article explains atomicity, thread safety, and thread‑unsafe behavior in Java, demonstrates a simple class with a volatile counter, runs two concurrent threads that increment it, shows the non‑atomic nature of i++, and analyzes why the final value may remain 1.

AtomicityThread Safetyconcurrency
0 likes · 4 min read
Why Incrementing a Counter Isn’t Thread‑Safe in Java: A Hands‑On Demo
FunTester
FunTester
Jul 14, 2019 · Fundamentals

Why a Simple Increment Fails in Multithreaded Java: A Concurrency Demo

This article explains atomicity, thread safety, and race conditions in Java by walking through a concrete example where multiple threads increment a shared volatile variable, showing why the non‑atomic i++ operation leads to inconsistent results.

AtomicityThread Safetyconcurrency
0 likes · 4 min read
Why a Simple Increment Fails in Multithreaded Java: A Concurrency Demo
Java Backend Technology
Java Backend Technology
Jun 27, 2019 · Backend Development

Is Your Java Singleton Really a Singleton? Thread, Reflection & Serialization Pitfalls

This article examines various Java singleton implementations—eager, lazy, double‑checked locking, static inner class, enum, and Kotlin object—analyzing their thread safety, reflection and serialization vulnerabilities, and shows how to harden them using volatile, constructor guards, and readResolve.

Design PatternEnumSerialization
0 likes · 12 min read
Is Your Java Singleton Really a Singleton? Thread, Reflection & Serialization Pitfalls
dbaplus Community
dbaplus Community
Jun 16, 2019 · Fundamentals

Understanding Thread Safety: From ThreadLocal to Locks and CAS

This article explains why thread safety concerns memory rather than threads, compares stack‑local and heap‑shared data, introduces ThreadLocal for per‑thread isolation, and covers mutual‑exclusion locks, optimistic CAS, and their appropriate use cases in concurrent programming.

CASJava concurrencyLocks
0 likes · 15 min read
Understanding Thread Safety: From ThreadLocal to Locks and CAS