Tagged articles

ThreadLocal

228 articles · Page 2 of 3
MaGe Linux Operations
MaGe Linux Operations
Nov 12, 2023 · Backend Development

Why RocketMQ Producers Need Load Balancing and How It Works

This article explains why load balancing is crucial for RocketMQ producers, details the internal selection algorithm using ThreadLocal indexes and round‑robin logic, and provides Java code examples illustrating how messages are distributed across queues.

JavaRocketMQThreadLocal
0 likes · 5 min read
Why RocketMQ Producers Need Load Balancing and How It Works
IT Services Circle
IT Services Circle
Nov 7, 2023 · Backend Development

Understanding ThreadLocal Memory Leaks and How to Prevent Them

This article explains the internal structure of ThreadLocal, identifies scenarios where ThreadLocal can cause memory leaks—especially in thread‑pool environments—analyzes the root causes, and provides practical techniques such as using remove() and expungeStaleEntry() to avoid these leaks.

ConcurrencyGarbage CollectionJava
0 likes · 11 min read
Understanding ThreadLocal Memory Leaks and How to Prevent Them
Sohu Tech Products
Sohu Tech Products
Oct 25, 2023 · Backend Development

Deep Analysis of Netty FastThreadLocal: From Production Issue to Source Code Implementation

The article traces a production bug where unreleased JDK ThreadLocal data corrupted user info, then compares JDK ThreadLocal with Netty’s FastThreadLocal, detailing their source‑code implementations, performance trade‑offs (O(n) vs O(1) access), memory‑leak risks, and recommends explicit remove() calls to avoid leaks.

Backend DevelopmentFastThreadLocalJava
0 likes · 15 min read
Deep Analysis of Netty FastThreadLocal: From Production Issue to Source Code Implementation
vivo Internet Technology
vivo Internet Technology
Oct 18, 2023 · Backend Development

Understanding JDK ThreadLocal and Netty FastThreadLocal: Implementation, Advantages, and Best Practices

The article compares JDK ThreadLocal and Netty FastThreadLocal, detailing their implementations, performance trade‑offs, and memory‑leak risks, illustrates a real‑world HTTPS bug caused by missing remove() calls, and recommends always cleaning up ThreadLocal values while noting FastThreadLocal’s O(1) access may not always outperform the JDK version.

ConcurrencyFastThreadLocalJava
0 likes · 17 min read
Understanding JDK ThreadLocal and Netty FastThreadLocal: Implementation, Advantages, and Best Practices
Spring Full-Stack Practical Cases
Spring Full-Stack Practical Cases
Oct 15, 2023 · Backend Development

How SpringBoot Injects HttpServletRequest via ThreadLocal: A Deep Dive

This article explores how SpringBoot 2.6.12 injects HttpServletRequest into controllers using JDK dynamic proxies and ThreadLocal, detailing the underlying ObjectFactoryDelegatingInvocationHandler, RequestObjectFactory, RequestContextHolder, and DispatcherServlet processing flow with code examples and explains why injecting HttpServletRequest and HttpServletResponse in a controller is safe.

DispatcherServletHttpServletRequestJava
0 likes · 7 min read
How SpringBoot Injects HttpServletRequest via ThreadLocal: A Deep Dive
Spring Full-Stack Practical Cases
Spring Full-Stack Practical Cases
Oct 8, 2023 · Backend Development

Spring Transaction Deep Dive: Thread‑Bound Connections and Multithreaded Consistency

This article explains Spring's transaction core, showing how TransactionInterceptor and TransactionAspectSupport use AOP to bind a Connection to ThreadLocal, walks through key code snippets for creating, committing, and rolling back transactions, and demonstrates a JUC‑based solution for maintaining transaction consistency across multiple threads.

JavaJdbcTemplateSpring
0 likes · 9 min read
Spring Transaction Deep Dive: Thread‑Bound Connections and Multithreaded Consistency
Code Ape Tech Column
Code Ape Tech Column
Sep 22, 2023 · Backend Development

Elegant Ways to Transfer Data Between Parent and Child Threads in Spring Boot

This article introduces four methods—manual setting, TaskDecorator, InheritableThreadLocal, and TransmittableThreadLocal—to propagate contextual data such as user information from a parent thread to child threads in Spring Boot asynchronous execution, providing code examples and practical recommendations.

Asynchronous ProgrammingJavaSpring Boot
0 likes · 13 min read
Elegant Ways to Transfer Data Between Parent and Child Threads in Spring Boot
Selected Java Interview Questions
Selected Java Interview Questions
Aug 31, 2023 · Backend Development

How to Solve SimpleDateFormat Thread Safety Issues in High-Concurrency Scenarios

This article presents several common solutions for addressing the thread‑safety problem of Java's SimpleDateFormat in high‑concurrency environments, including using local variables, synchronized blocks, Lock, ThreadLocal, Java 8 DateTimeFormatter, and Joda‑Time, and evaluates their performance and suitability.

ConcurrencyDateTimeFormatterJava
0 likes · 17 min read
How to Solve SimpleDateFormat Thread Safety Issues in High-Concurrency Scenarios
政采云技术
政采云技术
Aug 31, 2023 · Backend Development

Understanding Java ThreadLocal: Principles, Implementation, and Best Practices

ThreadLocal provides each Java thread with its own isolated variable copy, and this article explains its underlying mechanism, core methods (set, get, remove), internal ThreadLocalMap structure, practical code examples, common usage scenarios, and important considerations such as memory leaks and proper cleanup.

BackendConcurrencyJava
0 likes · 12 min read
Understanding Java ThreadLocal: Principles, Implementation, and Best Practices
Su San Talks Tech
Su San Talks Tech
Aug 24, 2023 · Backend Development

Simplify JWT Token Handling in Spring Using Custom Annotations & ThreadLocal

This article walks through the evolution of a Spring‑based JWT token validation solution, from passing HttpServletRequest into service methods to using a custom @NeedToken annotation, reflection, a base class, and finally ThreadLocal to ensure each request’s token is safely isolated in high‑concurrency environments.

AOPConcurrencyJWT
0 likes · 13 min read
Simplify JWT Token Handling in Spring Using Custom Annotations & ThreadLocal
FunTester
FunTester
Aug 2, 2023 · Backend Development

Practical Use of Java ThreadLocal for Thread‑Safe Variable Storage and Real‑World Scenarios

This article explains the Java ThreadLocal class, demonstrates how it provides per‑thread variable isolation to avoid concurrency issues, and shares two real‑world scenarios—including a utility class and a Spring Boot case—showing how ThreadLocal can simplify thread‑local state management while warning about potential memory leaks.

ConcurrencyJavaThread Safety
0 likes · 9 min read
Practical Use of Java ThreadLocal for Thread‑Safe Variable Storage and Real‑World Scenarios
Shepherd Advanced Notes
Shepherd Advanced Notes
Jul 17, 2023 · Fundamentals

How to Pass Values Between Parent and Child Threads with InheritableThreadLocal and TransmittableThreadLocal

The article explains why regular ThreadLocal cannot share data from a parent thread to its child, introduces InheritableThreadLocal as a built‑in solution, shows its limitation with thread‑pool reuse, and demonstrates how Alibaba's TransmittableThreadLocal overcomes this issue with concrete code examples and output.

ConcurrencyInheritableThreadLocalJava
0 likes · 10 min read
How to Pass Values Between Parent and Child Threads with InheritableThreadLocal and TransmittableThreadLocal
Cognitive Technology Team
Cognitive Technology Team
Jun 11, 2023 · Backend Development

Unified Handling of ThreadLocal Issues in Java Projects

This article explains why ThreadLocal can cause information loss, corruption, or OOM in Java applications and presents two practical approaches—Java agent bytecode manipulation and proxy‑based thread‑pool wrappers—along with concrete Spring Sleuth implementations and testing results to ensure safe propagation and cleanup.

AOPConcurrencyJava
0 likes · 5 min read
Unified Handling of ThreadLocal Issues in Java Projects
360 Quality & Efficiency
360 Quality & Efficiency
May 19, 2023 · Backend Development

Resolving SimpleDateFormat Thread Safety Issues with ThreadLocal in Java

This article explains why Java's SimpleDateFormat is not thread‑safe, demonstrates the concurrency problem with a multithreaded demo, and presents three solutions—creating new instances, synchronizing access, and using ThreadLocal—highlighting the ThreadLocal approach with code examples and discussion of potential memory‑leak considerations.

ConcurrencySimpleDateFormatThread Safety
0 likes · 4 min read
Resolving SimpleDateFormat Thread Safety Issues with ThreadLocal in Java
Meituan Technology Team
Meituan Technology Team
Apr 20, 2023 · Backend Development

Analyzing TraceId Loss in Spring @Async and Distributed Tracing Solutions

The article investigates a missing TraceId in a Spring @Async call, analyzes the underlying design of MTrace and Google Dapper, examines ThreadLocal propagation mechanisms, identifies SimpleAsyncTaskExecutor as the root cause, and presents a custom thread‑pool solution while comparing alternative distributed tracing systems.

JavaMTraceSimpleAsyncTaskExecutor
0 likes · 28 min read
Analyzing TraceId Loss in Spring @Async and Distributed Tracing Solutions
dbaplus Community
dbaplus Community
Feb 7, 2023 · Backend Development

How We Cut Log4j2 Disk and CPU Usage by 90% in a High‑Traffic Shopping Cart

Facing massive log volume in JD.com’s shopping cart service, we reduced disk consumption, CPU load, and improved request latency by applying Log4j2 log level filtering, asynchronous logging with AsyncLogger, and TTL‑based thread‑local context propagation, while providing detailed metrics, configuration steps, and best‑practice recommendations.

Performance OptimizationThreadLocalasynchronous logging
0 likes · 14 min read
How We Cut Log4j2 Disk and CPU Usage by 90% in a High‑Traffic Shopping Cart
IT Services Circle
IT Services Circle
Jan 15, 2023 · Backend Development

Understanding ThreadLocal and InheritableThreadLocal: Causes and Solutions for Missing Client Information in Multithreaded Java Services

This article explains why client information stored in ThreadLocal becomes unavailable after switching a single‑threaded search service to multithreading, analyzes the underlying ThreadLocal and InheritableThreadLocal mechanisms, and provides two practical solutions—passing the context manually or using InheritableThreadLocal—to avoid the upgrade‑prompt bug.

ConcurrencyInheritableThreadLocalJava
0 likes · 13 min read
Understanding ThreadLocal and InheritableThreadLocal: Causes and Solutions for Missing Client Information in Multithreaded Java Services
Code Ape Tech Column
Code Ape Tech Column
Jan 4, 2023 · Backend Development

Elegant Methods for Passing Data Between Parent and Child Threads in Spring Boot

This article explains four techniques—including manual setting, TaskDecorator, InheritableThreadLocal, and TransmittableThreadLocal—to reliably transfer user context and other thread‑local data from parent to child threads in Spring Boot asynchronous execution, with complete code samples and best‑practice recommendations.

BackendJavaSpring Boot
0 likes · 13 min read
Elegant Methods for Passing Data Between Parent and Child Threads in Spring Boot
Rare Earth Juejin Tech Community
Rare Earth Juejin Tech Community
Nov 28, 2022 · Fundamentals

Understanding ThreadLocal in Java: Creation, Usage, and Implementation Details

This article explains Java's ThreadLocal class, covering its purpose for thread‑local storage, core methods such as get, set, and remove, ways to set initial values via subclassing or withInitial, usage of InheritableThreadLocal for parent‑child thread data propagation, and the underlying implementation details.

InheritableThreadLocalJavaThread Isolation
0 likes · 12 min read
Understanding ThreadLocal in Java: Creation, Usage, and Implementation Details
Top Architect
Top Architect
Nov 24, 2022 · Backend Development

Using SLF4J MDC to Correlate Logs Across Threads in Java

This article explains how to use SLF4J's MDC feature to attach a request ID to log entries, demonstrates the limitation of MDC in asynchronous threads, and provides a decorator‑based solution (MDCRunnable) that propagates the context to child threads and thread pools.

JavaMDCThreadLocal
0 likes · 10 min read
Using SLF4J MDC to Correlate Logs Across Threads in Java
Code Ape Tech Column
Code Ape Tech Column
Nov 18, 2022 · Backend Development

Using SLF4J MDC to Correlate Logs Across Threads and Asynchronous Tasks in Java

This article explains how to use SLF4J's MDC to attach a request identifier to log entries, demonstrates the limitation of MDC in asynchronous threads, and provides a decorator‑pattern solution (MDCRunnable) that propagates the context, enabling reliable log correlation across threads in Java backend applications.

BackendDecoratorPatternJava
0 likes · 10 min read
Using SLF4J MDC to Correlate Logs Across Threads and Asynchronous Tasks in Java
Selected Java Interview Questions
Selected Java Interview Questions
Nov 17, 2022 · Backend Development

Spring Boot Login Authentication: Filters, Interceptors, AOP, ThreadLocal, and Parameter Resolver

This article presents a comprehensive Spring Boot tutorial on implementing non‑intrusive login authentication using three techniques—Filter, Interceptor, and AOP with custom annotations—plus extensions such as ThreadLocal storage and a Spring MVC argument resolver, complete with project setup, Maven dependencies, and test screenshots.

AOPInterceptorLogin Authentication
0 likes · 13 min read
Spring Boot Login Authentication: Filters, Interceptors, AOP, ThreadLocal, and Parameter Resolver
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.

ReentrantLockThread SynchronizationThreadLocal
0 likes · 6 min read
Four Common Ways to Implement Thread Synchronization in Java
Java Architect Essentials
Java Architect Essentials
Sep 26, 2022 · Backend Development

Understanding Netty's FastThreadLocal: Background, Implementation, and Usage

This article explains why Netty created FastThreadLocal, describes its internal design and source‑code analysis—including UnpaddedInternalThreadLocalMap, InternalThreadLocalMap, FastThreadLocalThread, and FastThreadLocal implementations—covers performance degradation in ordinary threads, outlines its three resource‑recycling mechanisms, and shows how it is used for ByteBuf allocation in Netty.

FastThreadLocalNettyThreadLocal
0 likes · 14 min read
Understanding Netty's FastThreadLocal: Background, Implementation, and Usage
Code Ape Tech Column
Code Ape Tech Column
Sep 16, 2022 · Backend Development

Ensuring Thread Safety for Spring Singleton Beans: Problems and Solutions

This article explains why Spring singleton beans can be unsafe in concurrent scenarios, demonstrates the issue with a controller example, and presents multiple solutions including changing bean scope, using ThreadLocal, avoiding member variables, employing concurrent collections, and leveraging distributed caches.

BackendBean ScopeSpring
0 likes · 8 min read
Ensuring Thread Safety for Spring Singleton Beans: Problems and Solutions
Programmer DD
Programmer DD
Aug 21, 2022 · Backend Development

Why PageHelper Can Break Your MyBatis Queries: Hidden ThreadLocal Pitfalls

This article examines unexpected bugs caused by PageHelper in a Java/MyBatis project—such as duplicate registrations, limited dropdown results, and password‑reset errors—traces them to ThreadLocal misuse, explains the library’s internal pagination flow, and offers practical fixes to avoid these pitfalls.

JavaMyBatisSQL
0 likes · 14 min read
Why PageHelper Can Break Your MyBatis Queries: Hidden ThreadLocal Pitfalls
Su San Talks Tech
Su San Talks Tech
Aug 14, 2022 · Backend Development

9 Hidden Pitfalls When Converting Synchronous Code to Multithreaded Execution

Switching from single‑threaded synchronous calls to multithreaded asynchronous execution can boost performance, but it also introduces nine common problems—including missing return values, data loss, ordering issues, thread‑safety bugs, ThreadLocal anomalies, OOM, high CPU usage, transaction failures, and service crashes—that developers must understand and mitigate.

ConcurrencyJavaThreadLocal
0 likes · 19 min read
9 Hidden Pitfalls When Converting Synchronous Code to Multithreaded Execution
Selected Java Interview Questions
Selected Java Interview Questions
Aug 13, 2022 · Backend Development

Understanding PageHelper Pagination Issues and ThreadLocal Management in MyBatis

This article explains how PageHelper integrates with MyBatis, analyzes common pagination bugs such as unexpected LIMIT clauses, duplicate registrations, and password‑reset errors, and demonstrates the internal ThreadLocal handling, startPage usage, and proper cleanup to avoid thread‑local pollution.

MyBatisThreadLocalpagehelper
0 likes · 12 min read
Understanding PageHelper Pagination Issues and ThreadLocal Management in MyBatis
Cognitive Technology Team
Cognitive Technology Team
Jul 24, 2022 · Fundamentals

Introduction to ThreadLocal in Java

ThreadLocal provides thread confinement in Java, allowing each thread to hold its own independent variable, which is useful for scenarios such as database connection isolation, transaction storage, lock-free concurrency, implicit parameter passing across functions, and highlights common pitfalls like information loss in thread pools and OOM risks.

ConcurrencyImplicit ParametersJava
0 likes · 5 min read
Introduction to ThreadLocal in Java
Java Architect Essentials
Java Architect Essentials
Jul 3, 2022 · Backend Development

Thread Safety Issues of SimpleDateFormat.parse() and format() Methods and Their Solutions

This article explains why SimpleDateFormat.parse() and SimpleDateFormat.format() are not thread‑safe in Java, analyzes the underlying causes involving shared Calendar objects, and presents three practical solutions—including per‑thread instances, synchronized blocks, and ThreadLocal usage—to eliminate concurrency bugs.

Date ParsingSimpleDateFormatThread Safety
0 likes · 11 min read
Thread Safety Issues of SimpleDateFormat.parse() and format() Methods and Their Solutions
Code Ape Tech Column
Code Ape Tech Column
Jun 2, 2022 · Backend Development

Using Alibaba's TransmittableThreadLocal to Propagate ThreadLocal Variables in Thread Pools

This article explains why InheritableThreadLocal fails in pooled threads, introduces Alibaba's TransmittableThreadLocal library, demonstrates how to wrap executors and rewrite code to correctly transmit ThreadLocal data across parent‑child threads in Java thread pools, and provides detailed implementation and usage examples.

ConcurrencyJavaThreadLocal
0 likes · 13 min read
Using Alibaba's TransmittableThreadLocal to Propagate ThreadLocal Variables in Thread Pools
DaTaobao Tech
DaTaobao Tech
May 25, 2022 · Backend Development

Best Practices for Java Thread Pools and ThreadLocal in Backend Development

The article outlines Java thread‑pool fundamentals, explains ThreadPoolExecutor parameters and Tomcat’s custom pool behavior, and provides best‑practice guidelines for creating pools directly, configuring rejection policies, and safely using ThreadLocal—including static declarations, proper cleanup, and avoiding memory‑leak pitfalls—to build stable, high‑performance backend services.

BackendConcurrencyJava
0 likes · 32 min read
Best Practices for Java Thread Pools and ThreadLocal in Backend Development
Java Backend Technology
Java Backend Technology
May 23, 2022 · Backend Development

Is Your Spring MVC Controller Thread‑Safe? Understand and Fix It

This article explains what thread safety means, demonstrates how a simple counter can become unsafe under concurrent requests, shows Java code examples of the problem and its synchronized solution, and provides practical guidelines for ensuring Spring MVC controllers remain thread‑safe by avoiding shared mutable state or using synchronization mechanisms such as synchronized blocks or ThreadLocal.

ControllerJava concurrencySpring MVC
0 likes · 5 min read
Is Your Spring MVC Controller Thread‑Safe? Understand and Fix It
Su San Talks Tech
Su San Talks Tech
May 14, 2022 · Backend Development

Unlocking ThreadLocal: How Java Manages Thread‑Local Data and Avoids Memory Leaks

This article explains why ThreadLocal is used in Java concurrency, dives into its internal implementation—including ThreadLocalMap, weak‑referenced keys, hash‑based indexing and resizing—covers common pitfalls such as memory leaks, and shows how InheritableThreadLocal and TransmittableThreadLocal can safely share data across child threads and thread pools.

ConcurrencyInheritableThreadLocalJava
0 likes · 24 min read
Unlocking ThreadLocal: How Java Manages Thread‑Local Data and Avoids Memory Leaks
Selected Java Interview Questions
Selected Java Interview Questions
May 5, 2022 · Backend Development

Understanding ThreadLocal in Java: Principles, Memory Leak Issues, and Proper Usage

This article explains Java's ThreadLocal mechanism, detailing its internal structure, including key methods like set, get, and remove, demonstrates how improper use can cause memory leaks, and provides best practices and examples for safe usage, including InheritableThreadLocal and real-world scenarios.

Best PracticesInheritableThreadLocalMemory Leak
0 likes · 18 min read
Understanding ThreadLocal in Java: Principles, Memory Leak Issues, and Proper Usage
Cognitive Technology Team
Cognitive Technology Team
Apr 25, 2022 · Backend Development

Preventing ThreadLocal Information Loss in Multithreaded Java Applications by Implementing Custom Runnable and Callable (Hystrix Example)

This article explains why ThreadLocal variables can lose their values when used across thread pools, and demonstrates how to create custom Runnable and Callable wrappers that propagate HystrixRequestContext to ensure reliable ThreadLocal transmission in multithreaded Java environments.

ConcurrencyContextPropagationHystrix
0 likes · 8 min read
Preventing ThreadLocal Information Loss in Multithreaded Java Applications by Implementing Custom Runnable and Callable (Hystrix Example)
Cognitive Technology Team
Cognitive Technology Team
Apr 24, 2022 · Backend Development

Pitfalls of Using ThreadLocal for User Context in Java Applications

Using ThreadLocal to store user information in Java web applications can lead to hidden failures such as loss of context and memory leaks, especially when thread pools are involved, so developers should restrict its usage to controller threads and employ static analysis tools to detect improper usage.

ConcurrencyJavaMemoryLeak
0 likes · 4 min read
Pitfalls of Using ThreadLocal for User Context in Java Applications
Selected Java Interview Questions
Selected Java Interview Questions
Apr 4, 2022 · Backend Development

Using InheritableThreadLocal to Access Parent ThreadLocal Values in Child Threads (Java)

This article explains how to make a child thread inherit the values stored in a parent thread's ThreadLocal by using InheritableThreadLocal, demonstrates the behavior with a runnable Java example, and details the underlying ThreadLocalMap mechanism that enables the inheritance.

Backend DevelopmentInheritableThreadLocalThreadLocal
0 likes · 3 min read
Using InheritableThreadLocal to Access Parent ThreadLocal Values in Child Threads (Java)
Dada Group Technology
Dada Group Technology
Mar 25, 2022 · Backend Development

Optimizing Log4j2 Logging: Reducing Disk and CPU Usage, Asynchronous Logging, and Traceability with ThreadLocal and TTL

This article presents a comprehensive approach to optimizing Log4j2 logging in high‑traffic Java services by reducing disk and CPU consumption through log level control and pattern tuning, adopting asynchronous logging, and enabling end‑to‑end request traceability using ThreadLocal, TransmittableThreadLocal, and MDC techniques, supported by performance test results and practical recommendations.

JavaResource OptimizationThreadLocal
0 likes · 14 min read
Optimizing Log4j2 Logging: Reducing Disk and CPU Usage, Asynchronous Logging, and Traceability with ThreadLocal and TTL
Top Architect
Top Architect
Jan 17, 2022 · Backend Development

Using SLF4J MDC to Correlate Logs Across Threads in Java Applications

This article explains how to employ SLF4J's MDC feature to attach a request identifier to log entries, demonstrates why it fails in asynchronous threads, and shows how to fix the issue with a decorator‑style MDCRunnable that propagates the MDC context to child threads and thread pools.

Decorator PatternJavaMDC
0 likes · 10 min read
Using SLF4J MDC to Correlate Logs Across Threads in Java Applications
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.

JavaMemory LeakThread Safety
0 likes · 8 min read
How Does Java’s ThreadLocal Avoid Memory Leaks? Deep Dive into Its Design
Programmer DD
Programmer DD
Oct 13, 2021 · Backend Development

Why Netty Introduced FastThreadLocal and How It Works

This article explains the motivation behind Netty's FastThreadLocal, compares it with JDK ThreadLocal, details its internal implementation—including InternalThreadLocalMap, FastThreadLocalThread, and key methods like get()—and discusses its performance benefits, resource recycling mechanisms, and practical usage in Netty's ByteBuf allocation.

FastThreadLocalJavaNetty
0 likes · 13 min read
Why Netty Introduced FastThreadLocal and How It Works
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.

Backend DevelopmentConcurrencyJava
0 likes · 10 min read
Mastering ThreadLocal in Java: When and How to Use It Safely
Spring Full-Stack Practical Cases
Spring Full-Stack Practical Cases
Sep 9, 2021 · Backend Development

Uncovering How SpringBoot Injects HttpServletRequest via ThreadLocal and Dynamic Proxies

This article explains how SpringBoot injects HttpServletRequest into controllers using a JDK dynamic proxy and ThreadLocal storage, tracing the request object from the ObjectFactoryDelegatingInvocationHandler through RequestObjectFactory, RequestContextHolder, and the FrameworkServlet's processRequest lifecycle.

Backend DevelopmentHttpServletRequestSpringBoot
0 likes · 7 min read
Uncovering How SpringBoot Injects HttpServletRequest via ThreadLocal and Dynamic Proxies
Wukong Talks Architecture
Wukong Talks Architecture
Aug 17, 2021 · Fundamentals

Core Java Multithreading Interview Questions and Concepts

This article compiles 16 classic Java multithreading interview questions covering high‑concurrency containers, CAS and ABA problems, volatile vs synchronized, the Java Memory Model, ThreadLocal drawbacks, AQS, thread‑pool architecture, queue types, sizing strategies, rejection policies, lifecycle management, and graceful shutdown techniques.

CASConcurrencyJava
0 likes · 20 min read
Core Java Multithreading Interview Questions and Concepts
Programmer DD
Programmer DD
Jul 23, 2021 · Fundamentals

Why Overriding hashCode Matters: Prevent Memory Leaks and OOM

This article explores the distinction between OutOfMemory errors and memory leaks in Java, examines how improper use of static fields, unclosed streams, incorrect equals/hashCode implementations, and ThreadLocal can cause leaks, and provides practical solutions and tools such as JVisualVM to detect and prevent these issues.

JVMJavaMemory Leak
0 likes · 16 min read
Why Overriding hashCode Matters: Prevent Memory Leaks and OOM
ITFLY8 Architecture Home
ITFLY8 Architecture Home
Jul 17, 2021 · Backend Development

How to Preserve Trace Context Across Asynchronous Java Threads with TransmittableThreadLocal

This article explains why ThreadLocal‑based trace information is lost in asynchronous Java calls, compares InheritableThreadLocal and the Alibaba‑provided TransmittableThreadLocal library, shows how to wrap runnables with TtlRunnable, and demonstrates a Java Agent solution for transparent thread‑pool propagation.

InheritableThreadLocalJavaThreadLocal
0 likes · 9 min read
How to Preserve Trace Context Across Asynchronous Java Threads with TransmittableThreadLocal
ITFLY8 Architecture Home
ITFLY8 Architecture Home
Jul 14, 2021 · Backend Development

Mastering SLF4J MDC for Precise Log Tracing in Multi‑Threaded Java Applications

This article explains how SLF4J’s Mapped Diagnostic Context (MDC) leverages ThreadLocal to embed trace and span identifiers into log messages, demonstrates configuring log4j2 patterns, shows code for injecting and clearing MDC values during span lifecycle, and addresses MDC propagation in asynchronous threads using Transmittable ThreadLocal.

MDCThreadLocallog4j2
0 likes · 4 min read
Mastering SLF4J MDC for Precise Log Tracing in Multi‑Threaded Java Applications
Su San Talks Tech
Su San Talks Tech
Jun 19, 2021 · Backend Development

How a Hidden NPE Revealed Deep Issues in Our Java Backend and RocketMQ Integration

After receiving a Sentry alert for a NullPointerException in a Java backend, the author traced the issue through user context handling with TransmittableThreadLocal, uncovered mismatched RocketMQ header propagation, multiple retry attempts, and a manual message injection, ultimately revealing how a missing header caused the NPE.

BackendNPERocketMQ
0 likes · 18 min read
How a Hidden NPE Revealed Deep Issues in Our Java Backend and RocketMQ Integration
IT Xianyu
IT Xianyu
Jun 16, 2021 · Databases

Understanding Database Connection Pools vs. ThreadLocal in Java

This article explains the fundamental differences between database connection pools and ThreadLocal‑cached connections in Java, illustrating how connection pools improve performance while ThreadLocal enables sharing a single connection across methods within the same thread for consistent transaction control, and discusses practical usage patterns.

Backend DevelopmentJavaThreadLocal
0 likes · 7 min read
Understanding Database Connection Pools vs. ThreadLocal in Java
Java Backend Technology
Java Backend Technology
May 29, 2021 · Backend Development

Avoid Hidden ThreadLocal Pitfalls: Memory Leaks, Context Loss in Thread Pools & Parallel Streams

This article explains three common ThreadLocal misuse traps—memory leaks caused by weak‑referenced keys, loss of thread‑local context in thread‑pool workers, and context disappearance in parallel streams—provides detailed code examples, and offers practical guidelines to prevent them in Java backend applications.

ConcurrencyJavaMemory Leak
0 likes · 9 min read
Avoid Hidden ThreadLocal Pitfalls: Memory Leaks, Context Loss in Thread Pools & Parallel Streams
Programmer DD
Programmer DD
May 21, 2021 · Backend Development

ThreadLocal & ConcurrentHashMap: Hidden Bugs in Java Concurrency

This article examines common misconceptions when using Java concurrency utilities such as ThreadLocal, ConcurrentHashMap, and CopyOnWriteArrayList, demonstrates real‑world bugs caused by thread reuse and improper atomic operations, and provides practical solutions—including explicit cleanup, proper locking, and high‑performance alternatives like computeIfAbsent and LongAdder—to ensure thread‑safe and efficient code.

ConcurrentHashMapCopyOnWriteArrayListJava
0 likes · 12 min read
ThreadLocal & ConcurrentHashMap: Hidden Bugs in Java Concurrency
Full-Stack Internet Architecture
Full-Stack Internet Architecture
May 19, 2021 · Backend Development

Understanding ThreadLocal in Java: Concepts, Memory‑Leak Risks, Source‑Code Walkthrough, and Best Practices

This article explains what ThreadLocal is, demonstrates how it works with and without it, analyses its source code, discusses potential memory‑leak issues, and provides best‑practice guidelines and a Spring‑Boot example for safe usage in multithreaded Java applications.

Best PracticesConcurrencyJava
0 likes · 12 min read
Understanding ThreadLocal in Java: Concepts, Memory‑Leak Risks, Source‑Code Walkthrough, and Best Practices
Top Architect
Top Architect
May 18, 2021 · Databases

Understanding Database Connection Pools and ThreadLocal in Java for Transaction Management

This article explains the fundamental differences between database connection pools and ThreadLocal, how each is used in Java to improve performance and enable cross‑method transaction control, and provides practical code examples and best‑practice guidelines for managing connections in multi‑threaded applications.

Backend DevelopmentDatabase Connection PoolJava
0 likes · 7 min read
Understanding Database Connection Pools and ThreadLocal in Java for Transaction Management
Java Backend Technology
Java Backend Technology
May 16, 2021 · Backend Development

Why ThreadLocal and Connection Pools Differ: Master Transaction Management in Java

This article explains the fundamental differences between database connection pools and ThreadLocal in Java, showing how pools improve performance while ThreadLocal enables sharing a single connection across a thread for seamless transaction control, and clarifies common misconceptions with code examples and practical insights.

JavaThreadLocalconnection pool
0 likes · 6 min read
Why ThreadLocal and Connection Pools Differ: Master Transaction Management 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.

ConcurrencyJavaThread Pool
0 likes · 20 min read
Using ThreadLocal in Java: Scenarios, Thread‑Safety Problems, and Practical Solutions
Java Backend Technology
Java Backend Technology
Mar 28, 2021 · Backend Development

Hidden Java Memory Leaks: 8 Common Pitfalls and How to Fix Them

This article explains eight typical Java memory‑leak scenarios—including unclosed resources, missing equals/hashCode, non‑static inner classes, overridden finalize, String.intern misuse, ThreadLocal traps, and static variables in web containers—provides code examples for each, and offers practical mitigation strategies.

FinalizeGarbage CollectionJava
0 likes · 11 min read
Hidden Java Memory Leaks: 8 Common Pitfalls and How to Fix Them
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.

ConcurrencyCopyOnWriteArrayListJava
0 likes · 11 min read
Understanding Thread Safety Issues in Java ArrayList and How to Fix Them
FunTester
FunTester
Feb 7, 2021 · Backend Development

Using ThreadLocal for Collect/Uncollect Performance Testing in Java

This article demonstrates how to apply Java's ThreadLocal together with an AtomicInteger to generate unique minisource_id values for a collect‑and‑uncollect workflow, and shows the complete code modifications and performance‑test script used to measure request latency.

BackendConcurrencyJava
0 likes · 6 min read
Using ThreadLocal for Collect/Uncollect Performance Testing in Java
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.

Backend DevelopmentConcurrencyJava
0 likes · 8 min read
Mastering Java ThreadLocal: Achieve Thread‑Safe Objects Without synchronized
vivo Internet Technology
vivo Internet Technology
Jan 27, 2021 · Backend Development

TransmittableThreadLocal Practice: Solving Multi-Country Business Context Propagation in E-commerce

The article explains how to reliably propagate country‑specific context across request handling, database access, and asynchronous thread pools in multi‑country e‑commerce by replacing simple ThreadLocal and InheritableThreadLocal with Alibaba’s TransmittableThreadLocal, demonstrating its integration with Spring MVC/Boot, MyBatis, Dubbo, and custom executors for both sharded and non‑sharded databases.

AlibabaInheritableThreadLocalJava concurrency
0 likes · 16 min read
TransmittableThreadLocal Practice: Solving Multi-Country Business Context Propagation in E-commerce
Code Ape Tech Column
Code Ape Tech Column
Dec 27, 2020 · Backend Development

Why ThreadLocal and ConcurrentHashMap Can Still Cause Bugs—and How to Fix Them

This article examines common misconceptions about Java concurrency utilities such as ThreadLocal, ConcurrentHashMap, and CopyOnWriteArrayList, demonstrates real‑world bugs caused by thread reuse and non‑atomic operations, and provides concrete solutions and performance‑tested alternatives.

ConcurrentHashMapCopyOnWriteArrayListJava concurrency
0 likes · 12 min read
Why ThreadLocal and ConcurrentHashMap Can Still Cause Bugs—and How to Fix Them
Selected Java Interview Questions
Selected Java Interview Questions
Dec 26, 2020 · Backend Development

Thread Reuse Pitfalls, ThreadLocal Misuse, and Proper Use of ConcurrentHashMap and CopyOnWriteArrayList

This article explains how thread reuse in a Tomcat thread pool can cause user‑information leakage when ThreadLocal is misused, analyzes the non‑atomic behavior of ConcurrentHashMap operations, demonstrates performance differences between locking and atomic methods, and warns against inappropriate use of CopyOnWriteArrayList in high‑write scenarios.

ConcurrentHashMapCopyOnWriteArrayListJava concurrency
0 likes · 13 min read
Thread Reuse Pitfalls, ThreadLocal Misuse, and Proper Use of ConcurrentHashMap and CopyOnWriteArrayList
vivo Internet Technology
vivo Internet Technology
Oct 22, 2020 · Backend Development

ThreadLocal Context Propagation with Hystrix

The article explains how to propagate ThreadLocal data such as a traceId across Hystrix’s thread‑pool isolation by implementing a custom HystrixConcurrencyStrategy or, more robustly, a HystrixCommandExecutionHook that uses HystrixRequestContext, ensuring the context is correctly transferred even to fallback methods.

ContextPropagationHystrixJava
0 likes · 12 min read
ThreadLocal Context Propagation with Hystrix
Code Ape Tech Column
Code Ape Tech Column
Oct 21, 2020 · Backend Development

Mastering Spring Boot: How to Integrate Multiple Data Sources with MyBatis

This tutorial explains how to configure Spring Boot with a single Druid data source, extend it to multiple dynamic data sources using AbstractRoutingDataSource, and seamlessly integrate MyBatis, including custom annotations, AOP switching, thread‑local isolation, and transaction management for robust multi‑database applications.

Dynamic Data SourceJavaMultiple Data Sources
0 likes · 18 min read
Mastering Spring Boot: How to Integrate Multiple Data Sources with MyBatis
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
Programmer DD
Programmer DD
Sep 29, 2020 · Backend Development

How ThreadLocal Works Internally and Why It Can Cause Memory Leaks

This article explains the internal mechanism of Java's ThreadLocal, how each thread maintains its own isolated map, why weak references are used for keys, and how improper cleanup in thread‑pool environments can lead to subtle memory‑leak problems.

Backend DevelopmentJavaMemory Leak
0 likes · 6 min read
How ThreadLocal Works Internally and Why It Can Cause Memory Leaks
Full-Stack Internet Architecture
Full-Stack Internet Architecture
Sep 18, 2020 · Backend Development

Optimizing Service Calls with ThreadLocal Cache and Custom Annotations in Java

The article explains how to reduce redundant service calls in Java back‑end systems by passing required data from upper layers, applying cache annotations, and implementing an elegant ThreadLocal‑based caching mechanism using custom annotations, aspects, and filters to improve performance without extensive code changes.

AspectJJavaThreadLocal
0 likes · 9 min read
Optimizing Service Calls with ThreadLocal Cache and Custom Annotations in Java
Programmer DD
Programmer DD
Aug 6, 2020 · Fundamentals

Why Overriding equals Without hashCode Can Cause Memory Leaks in Java

This article explores the distinction between OutOfMemory errors and memory leaks in Java, explains how improper use of static fields, unclosed streams, incorrect equals/hashCode implementations, and ThreadLocal can lead to leaks, and provides practical solutions and tools such as JVisualVM to detect and prevent them.

JVMMemory LeakOutOfMemory
0 likes · 14 min read
Why Overriding equals Without hashCode Can Cause Memory Leaks in Java
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.

ConcurrencyJavaMemory Leak
0 likes · 17 min read
Why Spring Beans Aren’t Thread‑Safe and How ThreadLocal Solves It
Top Architect
Top Architect
Jun 22, 2020 · Information Security

Implementing Token-Based Authentication, Anti‑DoS, and Repeat‑Submission Prevention in Spring Boot

This article explains how to design a secure token mechanism with timestamp validation, describes common DoS attack types, and provides practical Spring Boot code examples—including Redis configuration, token generation, interceptor logic, MD5 signing utilities, and ThreadLocal usage—to prevent repeat submissions and protect APIs.

DoS protectionJavaRedis
0 likes · 21 min read
Implementing Token-Based Authentication, Anti‑DoS, and Repeat‑Submission Prevention in Spring Boot
Selected Java Interview Questions
Selected Java Interview Questions
Jun 17, 2020 · Information Security

API Security Practices: Tokens, Timestamps, Signatures, and Anti‑Replay Measures with Java Examples

This article explains common API security mechanisms such as token and user token usage, timestamp validation, signature generation, anti‑replay strategies, DoS attack types, and provides Java Spring Boot code examples for token handling, request interception, custom annotations, and ThreadLocal utilities.

API SecurityDoS protectionJava Spring
0 likes · 22 min read
API Security Practices: Tokens, Timestamps, Signatures, and Anti‑Replay Measures with Java Examples
Java Captain
Java Captain
May 16, 2020 · Fundamentals

Deep Dive into Java ThreadLocal: Data Structure, Hash Algorithm, Cleanup, and Usage

This article provides an in‑depth analysis of Java’s ThreadLocal mechanism, covering its weak‑reference key, internal ThreadLocalMap structure, hash algorithm, collision resolution, cleanup strategies, expansion logic, source code walkthroughs, and practical usage scenarios such as trace‑ID propagation in distributed systems.

Garbage CollectionJavaThreadLocal
0 likes · 27 min read
Deep Dive into Java ThreadLocal: Data Structure, Hash Algorithm, Cleanup, and Usage
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.

Backend DevelopmentJavaThread Safety
0 likes · 16 min read
Understanding ThreadLocal in Java: Implementation, Memory‑Leak Risks, and Practical Use Cases