Tagged articles
ThreadLocalMap
10 articles · Page 1 of 1
This article explains how a static ThreadLocal without cleanup in a thread pool causes user data leakage and memory leaks, details ThreadLocalMap's weak-reference Entry structure, demonstrates InheritableThreadLocal's failure with pooled threads, and presents solutions including try-finally cleanup, interceptor-based clearing, Alibaba's TransmittableThreadLocal, and an AutoCloseable wrapper for safe scoping.
AutoCloseableInheritableThreadLocalJava Concurrency
0 likes · 10 min read


XikeSep 9, 2026 · Fundamentals
ThreadLocal provides per-thread variable copies via a ThreadLocalMap with weak-reference keys and strong-reference values, enabling request-context storage and non-thread-safe object reuse, but risks memory leaks in long-lived thread pools unless explicitly removed, and requires careful handling for cross-thread propagation.
Best PracticesInheritableThreadLocalJava Concurrency
0 likes · 14 min read

This article explains how ThreadLocal stores values per thread, details the internal set and get mechanisms, discusses potential memory‑leak problems caused by stale entries, and provides best‑practice guidelines such as using remove() and InheritableThreadLocal for child threads.
InheritableThreadLocalJavaMemoryLeak
0 likes · 9 min read

This article explains Java's ThreadLocal mechanism, detailing its internal ThreadLocalMap structure, core set/get/remove operations with full code examples, and demonstrates how multiple ThreadLocal variables are stored per thread, providing a clear understanding of thread‑local storage in backend development.
ConcurrencyJavaThreadLocal
0 likes · 6 min read


政采云技术Aug 31, 2023 · Backend Development
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

The article explains Java's ThreadLocal mechanism, detailing how each thread maintains its own ThreadLocalMap, provides practical code examples, examines the underlying source implementation—including set and get methods—and discusses potential memory‑leak pitfalls and ways to avoid them.
ConcurrencyJavaMemory Leak
0 likes · 11 min read

This article explains the inner workings of Java's ThreadLocal, covering its storage mechanism, ThreadLocalMap structure, get/set/remove operations, thread isolation, potential memory leak pitfalls, and provides a practical demo program to illustrate proper usage.
JavaMemory LeakThread Isolation
0 likes · 11 min read

This article explains how ThreadLocal works internally, demonstrates its typical use in a Spring single‑sign‑on interceptor, analyzes the source code of ThreadLocal and ThreadLocalMap, and reveals the conditions under which ThreadLocal can cause memory leaks, offering practical guidance to avoid them.
JavaMemory LeakSpring
0 likes · 20 min read

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.
Distributed TracingJavaThreadLocal
0 likes · 27 min read

ThreadLocal provides thread‑confined variables in Java, eliminating race conditions without synchronization; this article explains its concept, demonstrates usage with code examples, analyzes the underlying ThreadLocalMap implementation, discusses hash calculations, potential memory‑leak pitfalls, and outlines common application scenarios.
ConcurrencyJavaMemory Leak
0 likes · 15 min read
