Tagged articles

ThreadLocal

228 articles · Page 1 of 3
Java Captain
Java Captain
Sep 23, 2026 · Fundamentals

5 Common Java Memory Leak Scenarios and How to Detect Them

This article explains five common Java memory leak scenarios—long-lived collections, unclosed resources, ThreadLocal misuse, inner class references, and unregistered listeners—with code examples and recommends MAT and VisualVM for leak detection.

Garbage CollectionInner ClassJava
0 likes · 5 min read
5 Common Java Memory Leak Scenarios and How to Detect Them
liandk
liandk
Sep 22, 2026 · Backend Development

Java Memory Leak Deep Dive: 10 Hidden Scenarios, MAT Analysis & Prevention

This comprehensive guide covers 10 hidden Java memory leak scenarios, a 6-step MAT-based investigation SOP, code-level fixes for ThreadLocal and static collections, emergency mitigation tactics, and long-term prevention standards to eliminate recurring OOM crashes.

GCJVMJava
0 likes · 15 min read
Java Memory Leak Deep Dive: 10 Hidden Scenarios, MAT Analysis & Prevention
Xike
Xike
Sep 9, 2026 · Fundamentals

ThreadLocal Internals: How It Works, Why It Leaks, and Safe Usage Patterns

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
ThreadLocal Internals: How It Works, Why It Leaks, and Safe Usage Patterns
Java Tech Enthusiast
Java Tech Enthusiast
Sep 7, 2026 · Backend Development

Java Virtual Threads: Why Production Adoption Lagged Behind the Hype

The article analyzes why Java virtual threads, despite promising million-concurrency with minimal code changes, see little production adoption due to pinning with synchronized, ThreadLocal memory pressure, incomplete framework support, and CPU-bound workload mismatch, while showing benchmarks where they excel in I/O-heavy services but migration costs deter legacy systems.

ConcurrencyJDK 21Java
0 likes · 12 min read
Java Virtual Threads: Why Production Adoption Lagged Behind the Hype
macrozheng
macrozheng
Sep 7, 2026 · Backend Development

Java Virtual Threads: Why the 'Million Concurrency' Promise Failed in Production

This article analyzes why Java virtual threads, despite promising million-concurrency with minimal overhead, see little production adoption due to pinning with synchronized blocks, ThreadLocal memory explosions, incomplete framework support, and unsuitability for CPU-bound workloads, while showing benchmarks where they excel in I/O-heavy scenarios.

ConcurrencyJDK 21Java
0 likes · 12 min read
Java Virtual Threads: Why the 'Million Concurrency' Promise Failed in Production
LuTiao Programming
LuTiao Programming
Sep 2, 2026 · Backend Development

Spring Boot Multi-Tenancy: Why Data Source Routing Is the Easy Part

This article walks through a production-ready Spring Boot multi-tenancy implementation using database-per-tenant isolation, JWT-based tenant identification via Spring Security, AbstractRoutingDataSource for dynamic routing, and ThreadLocal context management, while exposing critical pitfalls in transaction timing, async task propagation, and dynamic tenant registration.

AbstractRoutingDataSourceDatabase Per TenantJWT
0 likes · 16 min read
Spring Boot Multi-Tenancy: Why Data Source Routing Is the Easy Part
Java Backend Technology
Java Backend Technology
Aug 25, 2026 · Backend Development

Are Java Virtual Threads Losing Their Momentum?

The article examines why the early hype around Java virtual threads has faded, detailing technical pitfalls such as pinning and ThreadLocal memory bloat, incomplete ecosystem support, and misuse in CPU‑bound workloads, while also presenting benchmark data that shows they still excel in I/O‑heavy scenarios.

ConcurrencyJDKJava
0 likes · 10 min read
Are Java Virtual Threads Losing Their Momentum?
Dabaoshi
Dabaoshi
Aug 21, 2026 · Backend Development

Concurrency Series Finale: Virtual Threads and Structured Concurrency

The article explains why platform threads are costly, how JDK 21 virtual threads eliminate that cost, and provides practical guidance on creating, using, and debugging virtual threads, including pinning pitfalls, rules against pooling, structured concurrency, ScopedValue, and a detailed model‑selection comparison.

ConcurrencyJDK 21Java
0 likes · 34 min read
Concurrency Series Finale: Virtual Threads and Structured Concurrency
Random Bulletin
Random Bulletin
Jul 24, 2026 · Backend Development

Context Propagation at Ten‑Million QPS: From ThreadLocal to Explicit

The article examines a real‑world incident where ThreadLocal leakage caused user data mix‑ups, then walks through the evolution of context propagation—from implicit ThreadLocal to TTL patches, Reactor Context, ScopedValue, and Go's explicit context—highlighting trade‑offs and best practices for high‑throughput systems.

ConcurrencyContextPropagationGoContext
0 likes · 15 min read
Context Propagation at Ten‑Million QPS: From ThreadLocal to Explicit
Coder Trainee
Coder Trainee
Jul 12, 2026 · Backend Development

10 Must‑Know Java Concurrency Interview Questions

This article walks through ten essential Java concurrency interview topics—including the Java Memory Model, volatile semantics, synchronized lock upgrades, CAS pitfalls, AQS internals, ReentrantLock versus synchronized, ThreadPoolExecutor parameters, ThreadLocal memory‑leak issues, CountDownLatch vs CyclicBarrier, and deadlock conditions—providing code snippets, tables and detailed explanations to help candidates answer interview questions confidently.

AQSCASConcurrency
0 likes · 12 min read
10 Must‑Know Java Concurrency Interview Questions
Coder Trainee
Coder Trainee
Jul 9, 2026 · Backend Development

Java Concurrency Deep Dive – Part 8: Real‑World Pitfalls and Post‑mortem

This article reviews common Java concurrency pitfalls—including deadlocks, ThreadLocal memory leaks, Integer‑cache loops, unbounded thread‑pool queues, and swallowed exceptions—illustrates each with code samples, analyzes real production incidents, and provides a concise checklist and tool‑selection guide for safe concurrent programming.

Best PracticesConcurrencyConcurrentHashMap
0 likes · 9 min read
Java Concurrency Deep Dive – Part 8: Real‑World Pitfalls and Post‑mortem
Programmer1970
Programmer1970
Jun 29, 2026 · Backend Development

How We Cut Full GC from 10 seconds to 200 ms: A Complete JVM GC Tuning Guide

A production outage at 3 am revealed a 10‑second Full GC pause on an 8 GB heap; the article walks through evidence collection, heap‑size rebalancing, switching to G1, fine‑tuning G1 parameters, and code changes that together reduced Full GC pauses to 200 ms and improved latency dramatically.

Full GCG1 GCGC Tuning
0 likes · 12 min read
How We Cut Full GC from 10 seconds to 200 ms: A Complete JVM GC Tuning Guide
Xiaolin Talks Programming
Xiaolin Talks Programming
Jun 26, 2026 · Backend Development

Multi-Tenant SaaS in Production: Spring Boot Dynamic Data Source & Row-Level Isolation

This article shares production-hardened patterns for multi-tenant SaaS using Spring Boot, covering isolation mode selection, ThreadLocal-based context propagation, MyBatis-Plus SQL interception for automatic tenant_id injection, Feign and async thread propagation, HikariCP tuning, composite indexing, cursor pagination, and real-world pitfalls like interceptor ordering, transaction-bound data source switching, and ThreadLocal leakage.

Dynamic Data SourceFeignMyBatis-Plus
0 likes · 19 min read
Multi-Tenant SaaS in Production: Spring Boot Dynamic Data Source & Row-Level Isolation
samdeepthink
samdeepthink
Jun 1, 2026 · Backend Development

Why One ThreadLocal Instance Suffices for an Entire Business Scenario

The article explains that a single ThreadLocal object can be shared across dozens of threads because the actual data lives in each thread's own ThreadLocalMap, outlines how set/get work, highlights thread‑pool pitfalls such as stale data and memory leaks, and provides best‑practice guidelines for static declaration, proper removal, and using TransmittableThreadLocal for cross‑thread propagation.

ConcurrencyJavaMemory Leak
0 likes · 10 min read
Why One ThreadLocal Instance Suffices for an Entire Business Scenario
Lobster Programming
Lobster Programming
May 18, 2026 · Fundamentals

Why userId Gets Lost in Async Calls and How ThreadLocal Solves It

The article explains ThreadLocal's lifecycle, why userId disappears when spawning asynchronous threads, compares ThreadLocal, InheritableThreadLocal, and Alibaba's TransmittableThreadLocal, and shows how the latter prevents data contamination in thread‑pool reuse.

InheritableThreadLocalJava concurrencyThread Pool
0 likes · 5 min read
Why userId Gets Lost in Async Calls and How ThreadLocal Solves It
CodeNotes
CodeNotes
May 4, 2026 · Backend Development

Mastering ThreadLocal in Java: Core Principles, Real‑World Scenarios & Best Practices

This article explains how ThreadLocal provides per‑thread variable copies in Java web applications, details its internal storage in Thread objects, showcases ten practical scenarios—from request tracing to async tasks—and highlights common pitfalls such as memory leaks and thread‑pool data contamination, offering concrete best‑practice recommendations.

ConcurrencyJavaMemoryLeak
0 likes · 23 min read
Mastering ThreadLocal in Java: Core Principles, Real‑World Scenarios & Best Practices
Spring Full-Stack Practical Cases
Spring Full-Stack Practical Cases
Apr 22, 2026 · Backend Development

5 Common Spring Boot Filter Pitfalls and How to Avoid Them

This article examines five typical pitfalls when using Spring Boot filters—request body consumption, ThreadLocal leakage, duplicate execution, ordering conflicts, and async handling—provides concrete code examples, explains why each issue occurs, and offers reliable solutions to keep your applications stable and secure.

BackendJavaServlet
0 likes · 11 min read
5 Common Spring Boot Filter Pitfalls and How to Avoid Them
WeiLi Technology Team
WeiLi Technology Team
Mar 31, 2026 · Backend Development

Why ThreadLocal Leaks Cause Full GC in Thread Pools and How to Fix It

An online service experienced frequent Full GC due to a ThreadLocal memory leak in a thread‑pool scenario; the article walks through GC log analysis, heap dump inspection, root‑cause discovery in ThreadFactory logic, and presents a robust fix using Spring’s TaskDecorator to ensure proper cleanup.

GCJavaMemory Leak
0 likes · 14 min read
Why ThreadLocal Leaks Cause Full GC in Thread Pools and How to Fix It
JavaGuide
JavaGuide
Feb 11, 2026 · Backend Development

Do ThreadLocal Values Fail in Asynchronous Scenarios? An Interviewer's Trick Question Explained

This article explains why ThreadLocal values are not automatically transferred in asynchronous or thread‑pool contexts, compares JDK's InheritableThreadLocal with Alibaba's TransmittableThreadLocal (TTL), and shows how TTL captures, replays, and restores context safely with code examples and diagrams.

InheritableThreadLocalJava concurrencyThreadLocal
0 likes · 13 min read
Do ThreadLocal Values Fail in Asynchronous Scenarios? An Interviewer's Trick Question Explained
Java Companion
Java Companion
Feb 5, 2026 · Backend Development

Elegant Dynamic Data Source Switching in SpringBoot Using ThreadLocal and AbstractRoutingDataSource

This article walks through building an elegant dynamic data‑source switch in SpringBoot by combining ThreadLocal with AbstractRoutingDataSource, covering the context holder, custom routing class, YAML configuration, testing, annotation‑driven switching, and runtime addition of new data sources.

AOPAbstractRoutingDataSourceMyBatis-Plus
0 likes · 16 min read
Elegant Dynamic Data Source Switching in SpringBoot Using ThreadLocal and AbstractRoutingDataSource
SpringMeng
SpringMeng
Jan 16, 2026 · Backend Development

What Unexpected Pitfalls PageHelper Can Teach You After Years of Use

The article recounts a developer’s painful experience with PageHelper, detailing how duplicate registrations, truncated result sets, and password‑update errors stem from the plugin’s ThreadLocal pagination handling, and explains the underlying code paths and safe usage practices.

BackendJavaMyBatis
0 likes · 13 min read
What Unexpected Pitfalls PageHelper Can Teach You After Years of Use
macrozheng
macrozheng
Jan 6, 2026 · Backend Development

Why PageHelper Can Break Your MyBatis Queries and How to Fix It

The article examines unexpected bugs caused by PageHelper’s hidden LIMIT clause injection in MyBatis projects, explains how ThreadLocal pagination parameters persist across requests, and provides practical guidelines and code examples to avoid and clean up these issues.

JavaMyBatisThreadLocal
0 likes · 13 min read
Why PageHelper Can Break Your MyBatis Queries and How to Fix It
Top Architect
Top Architect
Dec 25, 2025 · Backend Development

Auto‑Inject UserId and OrderId into Logs with Spring AOP and MDC

This guide shows how to eliminate manual logging of user and order identifiers in a Java e‑commerce system by declaring log placeholders, storing values in ThreadLocal, and using a custom @UserLog annotation with Spring AOP to automatically populate MDC variables for Log4j2.

AOPJavaMDC
0 likes · 9 min read
Auto‑Inject UserId and OrderId into Logs with Spring AOP and MDC
macrozheng
macrozheng
Nov 21, 2025 · Backend Development

Master Java Concurrency: Locks, Singleton Patterns, ThreadLocal, Reflection and More

This article provides a comprehensive guide to Java concurrency and related concepts, covering synchronized lock upgrades, object vs class locks, lazy and double‑checked singleton implementations, ThreadLocal mechanics, reflection usage, annotation scopes, JVM class loading, and Redis cluster threading behavior.

ConcurrencyJVMJava
0 likes · 22 min read
Master Java Concurrency: Locks, Singleton Patterns, ThreadLocal, Reflection and More
JavaGuide
JavaGuide
Nov 20, 2025 · Backend Development

iFlytek Salary Offers Revealed + Comprehensive Java Interview Prep

The article shares iFlytek's recent campus salary packages, then dives into a detailed Java interview guide covering Redis data types, key expiration handling, thread safety, ThreadLocal usage, MySQL covering and composite indexes, slow‑query analysis, and SQL‑injection prevention techniques.

Covering IndexJava InterviewMySQL
0 likes · 17 min read
iFlytek Salary Offers Revealed + Comprehensive Java Interview Prep
Tech Freedom Circle
Tech Freedom Circle
Nov 11, 2025 · Backend Development

ThreadLocal Interview Deep Dive: 20‑Minute Analysis, Manual vs Framework Solutions, and a Winning Methodology

This article explains the inner workings of Java's ThreadLocal, why it fails to propagate context in asynchronous scenarios, compares manual passing and decorator‑based approaches, introduces the TransmittableThreadLocal (TTL) library with its CRER workflow, and provides a structured interview answer that showcases deep architectural insight.

ConcurrencyContextPropagationJava
0 likes · 26 min read
ThreadLocal Interview Deep Dive: 20‑Minute Analysis, Manual vs Framework Solutions, and a Winning Methodology
Tech Freedom Circle
Tech Freedom Circle
Nov 4, 2025 · Backend Development

Designing a Non‑Intrusive Spring Cloud SaaS Multi‑Tenant Component for Full‑Stack Data Isolation

The article presents a step‑by‑step, code‑driven design of a Spring Cloud SaaS multi‑tenant solution that balances resource sharing and strict data isolation by using a shared‑database, shared‑schema approach with tenant_id filtering, ThreadLocal context, MyBatis‑Plus interceptors, Redis key prefixing, Sa‑Token session segregation, and Spring Boot auto‑configuration.

MyBatis-PlusRedisSa-Token
0 likes · 16 min read
Designing a Non‑Intrusive Spring Cloud SaaS Multi‑Tenant Component for Full‑Stack Data Isolation
IT Services Circle
IT Services Circle
Nov 2, 2025 · Backend Development

Why ScopedValue Is the Future Replacement for ThreadLocal in Java

This article explores the limitations of ThreadLocal—memory leaks, data contamination, inheritance issues, and performance overhead—and introduces Java's ScopedValue as a safer, more efficient alternative, covering its core design, basic and advanced usage, performance benchmarks, migration strategies, and real‑world web application examples.

ConcurrencyJavaScopedValue
0 likes · 28 min read
Why ScopedValue Is the Future Replacement for ThreadLocal in Java
Su San Talks Tech
Su San Talks Tech
Nov 1, 2025 · Backend Development

Why ScopedValue Is the Future of Thread-Local Data in Java

This article explores the limitations of ThreadLocal, introduces Java's new ScopedValue feature, provides detailed usage examples, performance benchmarks, migration strategies, and compares both approaches to help developers decide when and how to adopt ScopedValue in modern backend applications.

ConcurrencyJavaScopedValue
0 likes · 34 min read
Why ScopedValue Is the Future of Thread-Local Data in Java
IT Services Circle
IT Services Circle
Oct 31, 2025 · Backend Development

Master Java Concurrency, Singleton, ThreadLocal, and Reflection for Interviews

This guide covers essential Java interview topics—including synchronized lock upgrades, object vs class locking, lazy and double‑checked singleton patterns, ThreadLocal mechanics, reflection usage, annotation scopes, Redis cluster behavior, and a linear‑time algorithm challenge—providing clear explanations, code examples, and practical insights for developers preparing for technical interviews.

ConcurrencyJavaThreadLocal
0 likes · 20 min read
Master Java Concurrency, Singleton, ThreadLocal, and Reflection for Interviews
DeWu Technology
DeWu Technology
Oct 13, 2025 · Backend Development

TTL Agent Pitfalls: Memory Leaks & CPU Spikes in Java – Cases & Fixes

This article explains how the Transmittable ThreadLocal (TTL) Java agent works, why improper usage can cause context contamination, memory leaks, and CPU spikes, and provides real production cases, code examples, and practical recommendations to avoid these pitfalls.

ConcurrencyJava AgentMemory Leak
0 likes · 15 min read
TTL Agent Pitfalls: Memory Leaks & CPU Spikes in Java – Cases & Fixes
Architect's Tech Stack
Architect's Tech Stack
Sep 25, 2025 · Backend Development

Auto‑Inject UserId and OrderId into Logs with Spring AOP and MDC

This article explains how to eliminate manual logging of user and order identifiers in Java e‑commerce services by using Log4j2 placeholders, ThreadLocal, MDC, a custom @UserLog annotation, and Spring AOP to automatically enrich log messages with these contextual fields.

Java loggingMDCSpring AOP
0 likes · 9 min read
Auto‑Inject UserId and OrderId into Logs with Spring AOP and MDC
Java Architecture Diary
Java Architecture Diary
Sep 19, 2025 · Backend Development

Why ScopedValues Outperform ThreadLocal for Safe Context Management in Java

ScopedValues provide a more efficient, memory‑safe, and virtual‑thread‑friendly alternative to ThreadLocal for managing per‑thread context in Java, eliminating manual cleanup, reducing memory leaks, and simplifying context propagation across threads, as demonstrated by code examples and performance benchmarks.

ConcurrencyScopedValuesThreadLocal
0 likes · 6 min read
Why ScopedValues Outperform ThreadLocal for Safe Context Management in Java
macrozheng
macrozheng
Aug 8, 2025 · Backend Development

Master Java Backend: ThreadLocal, Memory Leaks, Spring Bean Lifecycle & AOP

This guide covers evaluating engineer hourly wages, interview self‑introduction tips, local vs distributed cache choices, ThreadLocal usage, memory‑leak detection with MAT, deadlock troubleshooting, Spring Bean lifecycle, AOP implementation, and Redis‑based distributed locks, plus resources for Spring Boot projects.

AOPJavaMemory Leak
0 likes · 20 min read
Master Java Backend: ThreadLocal, Memory Leaks, Spring Bean Lifecycle & AOP
FunTester
FunTester
Jul 20, 2025 · Backend Development

Which GUID Generation Method Wins? Performance Test of UUID, Snowflake, ThreadLocal & Atomic

An extensive performance benchmark compares four GUID generation techniques—UUID, Snowflake algorithm, ThreadLocal exclusive counters, and atomic counters—across varying thread counts, revealing that ThreadLocal excels in high‑concurrency single‑machine scenarios while Snowflake remains stable for distributed use, with detailed optimization recommendations.

GUIDJavaSnowflake
0 likes · 10 min read
Which GUID Generation Method Wins? Performance Test of UUID, Snowflake, ThreadLocal & Atomic
The Dominant Programmer
The Dominant Programmer
Jul 9, 2025 · Fundamentals

Mastering Java Thread Communication: volatile, synchronized, wait/notify, and Piped Streams

This article explains how Java threads interact using volatile for visibility, synchronized blocks for mutual exclusion, wait/notify (and Condition) for coordination, piped streams for one‑way byte communication, as well as Thread.join and ThreadLocal utilities, providing concrete code examples, best‑practice guidelines, and performance considerations.

ConcurrencyJavaPipedStream
0 likes · 23 min read
Mastering Java Thread Communication: volatile, synchronized, wait/notify, and Piped Streams
Java Backend Technology
Java Backend Technology
Jul 8, 2025 · Backend Development

ThreadLocal vs ScopedValue: Why ScopedValue Is the New King in Java Concurrency

ThreadLocal has long served as Java’s go‑to tool for thread‑local data, but its memory‑leak risks and performance penalties become pronounced with virtual threads, while the newer ScopedValue offers automatic cleanup, immutable safety, and superior efficiency, making it a compelling replacement in high‑concurrency scenarios.

ConcurrencyScopedValueThreadLocal
0 likes · 12 min read
ThreadLocal vs ScopedValue: Why ScopedValue Is the New King in Java Concurrency
Architect's Guide
Architect's Guide
Jul 7, 2025 · Backend Development

Dynamic Data Source Switching in Spring Boot Using ThreadLocal & AbstractRoutingDataSource

This tutorial explains how to implement dynamic data source switching in Spring Boot by combining ThreadLocal with AbstractRoutingDataSource, covering custom context holders, configuration, annotation‑driven switching, dynamic addition of data sources, and complete code examples with test results.

AbstractRoutingDataSourceDynamic Data SourceMyBatis-Plus
0 likes · 16 min read
Dynamic Data Source Switching in Spring Boot Using ThreadLocal & AbstractRoutingDataSource
Architect's Must-Have
Architect's Must-Have
Jun 9, 2025 · Backend Development

Why Netty Introduced FastThreadLocal and How It Boosts Performance

FastThreadLocal, Netty’s custom thread‑local implementation, replaces JDK’s ThreadLocal by using an indexed array to avoid hash collisions, offering faster access; this article explains its background, core classes, source‑code mechanics, performance trade‑offs, and cleanup strategies within Netty’s architecture.

FastThreadLocalJavaNetty
0 likes · 13 min read
Why Netty Introduced FastThreadLocal and How It Boosts Performance
Lobster Programming
Lobster Programming
Jun 3, 2025 · Backend Development

How ThreadLocal Can Cause Memory Leaks in Java Multithreading

This article explains how ThreadLocal creates per‑thread variable copies, demonstrates its usage with sample Java code, illustrates the internal storage structure, and reveals why improper handling can lead to memory leaks when thread‑local values persist in thread pools.

JavaMemory LeakThreadLocal
0 likes · 3 min read
How ThreadLocal Can Cause Memory Leaks in Java Multithreading
Java Backend Technology
Java Backend Technology
May 15, 2025 · Backend Development

Why Netty Uses FastThreadLocal Over JDK ThreadLocal: Deep Dive & Code Analysis

This article explains why Netty introduces FastThreadLocal instead of relying on JDK ThreadLocal, detailing its background, core principles, source code structure—including InternalThreadLocalMap, FastThreadLocalThread, and FastThreadLocal implementations—performance implications, resource reclamation mechanisms, and practical usage within Netty’s memory allocation.

FastThreadLocalNettyThreadLocal
0 likes · 11 min read
Why Netty Uses FastThreadLocal Over JDK ThreadLocal: Deep Dive & Code Analysis
Selected Java Interview Questions
Selected Java Interview Questions
May 14, 2025 · Backend Development

Enterprise Java Core Features: Full‑Chain Logging, Unified Exception Handling, Permission Interceptor, and Thread Context Management

This article presents a comprehensive guide to implementing full‑chain log tracing, unified exception handling, permission interception, request latency monitoring, and standardized log formats in enterprise‑level Java projects using Spring AOP, thread‑local context, and Redis caching.

AOPExceptionHandlingSecurity
0 likes · 23 min read
Enterprise Java Core Features: Full‑Chain Logging, Unified Exception Handling, Permission Interceptor, and Thread Context Management
Lin is Dream
Lin is Dream
May 5, 2025 · Backend Development

Mastering MDC with Logback: Traceable Logging for Distributed Systems

This article explains how to use SLF4J's MDC with Logback to assign a unique trace ID to each request, propagate it across threads and services, and configure log patterns so that logs become fully traceable for easier debugging in distributed systems.

JavaMDCThreadLocal
0 likes · 7 min read
Mastering MDC with Logback: Traceable Logging for Distributed Systems
Cognitive Technology Team
Cognitive Technology Team
May 4, 2025 · Backend Development

Understanding Java ThreadLocal Memory Leaks: Mechanisms, Risks, Diagnosis, and Defensive Practices

This article explains the inner workings of Java's ThreadLocal, analyzes how weak and strong references can cause memory leaks in thread pools, demonstrates typical leak scenarios with code examples, and provides diagnostic tools and defensive coding practices to prevent such leaks.

Best PracticesConcurrencyGarbage Collection
0 likes · 9 min read
Understanding Java ThreadLocal Memory Leaks: Mechanisms, Risks, Diagnosis, and Defensive Practices
Cognitive Technology Team
Cognitive Technology Team
May 3, 2025 · Fundamentals

Understanding Java ThreadLocalMap: Structure, Operations, and Memory Management

This article explains the internal design of Java's ThreadLocalMap, covering its core Entry structure, hash table storage, linear probing for collision resolution, key operations (set, get, remove), memory‑leak scenarios, automatic cleanup mechanisms, and practical usage patterns such as thread‑context propagation and Android Looper.

ConcurrencyJavaMemoryManagement
0 likes · 10 min read
Understanding Java ThreadLocalMap: Structure, Operations, and Memory Management
Cognitive Technology Team
Cognitive Technology Team
May 3, 2025 · Backend Development

Understanding ThreadLocal: Core Principles, Use Cases, Pitfalls, and Best Practices

ThreadLocal provides per‑thread variable storage to achieve thread isolation, improving concurrency performance, and is essential for safe data handling in Java, but improper use can cause memory leaks, data contamination, and other issues; this article explains its internal mechanism, common scenarios, pitfalls, and best‑practice guidelines with code examples.

Best PracticesConcurrencyJava
0 likes · 19 min read
Understanding ThreadLocal: Core Principles, Use Cases, Pitfalls, and Best Practices
Java Backend Full-Stack
Java Backend Full-Stack
Apr 26, 2025 · Backend Development

Master ThreadLocal: Answer Interview Questions and Prevent OOM Leaks

This article explains ThreadLocal’s internal mechanism, why improper use can cause OutOfMemoryError in thread pools, demonstrates the issue with a Java example, and provides best‑practice guidance—especially calling remove()—to prevent memory leaks while preparing for interview questions.

ConcurrencyJavaMemory Leak
0 likes · 11 min read
Master ThreadLocal: Answer Interview Questions and Prevent OOM Leaks
Java Architect Essentials
Java Architect Essentials
Apr 10, 2025 · Backend Development

Master Dynamic Data Source Switching in SpringBoot: A Step‑by‑Step Guide

This article walks through the complete process of implementing dynamic data source switching in a SpringBoot application, covering the core concepts of thread‑local context, abstract routing, custom annotations with AOP, configuration, code examples, and important considerations such as transaction management and performance.

AOPJavaSpringBoot
0 likes · 6 min read
Master Dynamic Data Source Switching in SpringBoot: A Step‑by‑Step Guide
Selected Java Interview Questions
Selected Java Interview Questions
Apr 10, 2025 · Backend Development

Understanding PageHelper Issues and ThreadLocal Pitfalls in MyBatis

This article analyzes unexpected behaviors caused by PageHelper in a Java backend project, such as duplicate user registration, limited query results, and password‑reset errors, and explains how ThreadLocal pagination parameters, startPage(), and cleanup mechanisms lead to these problems while offering practical debugging tips.

BackendMyBatisSQL
0 likes · 11 min read
Understanding PageHelper Issues and ThreadLocal Pitfalls in MyBatis
Architect's Must-Have
Architect's Must-Have
Mar 18, 2025 · Backend Development

Why Netty Uses FastThreadLocal and How It Outperforms JDK ThreadLocal

This article explains the motivation behind Netty's FastThreadLocal, details its internal design using an indexed array to avoid hash collisions, analyzes the core source code of InternalThreadLocalMap, FastThreadLocalThread, and FastThreadLocal, and discusses performance implications and reclamation strategies.

ConcurrencyFastThreadLocalJava
0 likes · 10 min read
Why Netty Uses FastThreadLocal and How It Outperforms JDK ThreadLocal
Selected Java Interview Questions
Selected Java Interview Questions
Mar 13, 2025 · Backend Development

Implementing Dynamic Data Source Switching in Spring Boot with ThreadLocal and AbstractRoutingDataSource

This article demonstrates how to build a dynamic data source switching mechanism in Spring Boot by leveraging ThreadLocal for thread‑scoped context and AbstractRoutingDataSource for routing, covering manual implementation, annotation‑driven switching, and runtime addition of new data sources.

AbstractRoutingDataSourceDynamicDataSourceMybatisPlus
0 likes · 14 min read
Implementing Dynamic Data Source Switching in Spring Boot with ThreadLocal and AbstractRoutingDataSource
Architect
Architect
Mar 12, 2025 · Backend Development

DataSource Switching in Spring Boot with ThreadLocal & AbstractRoutingDataSource

Facing the need to query multiple databases in a Spring Boot application, this guide walks through building a custom dynamic datasource solution using ThreadLocal and AbstractRoutingDataSource, covering core implementations, annotation‑based switching, dynamic datasource addition, configuration, and comprehensive test results.

AbstractRoutingDataSourceJavaMyBatis-Plus
0 likes · 18 min read
DataSource Switching in Spring Boot with ThreadLocal & AbstractRoutingDataSource
FunTester
FunTester
Jan 20, 2025 · Fundamentals

Mastering ThreadLocal in Java: From Basics to Best Practices

ThreadLocal provides a simple yet powerful way to give each thread its own independent variable, eliminating shared-state conflicts; this guide explains its underlying mechanism, creation methods, basic get/set operations, a complete example with console output, and important usage considerations such as potential memory leaks.

ConcurrencyJavaThreadLocal
0 likes · 6 min read
Mastering ThreadLocal in Java: From Basics to Best Practices
Xuanwu Backend Tech Stack
Xuanwu Backend Tech Stack
Jan 14, 2025 · Backend Development

Mastering Java ThreadLocal: Core Operations, Map Structure, and Practical Examples

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.

Backend DevelopmentConcurrencyJava
0 likes · 6 min read
Mastering Java ThreadLocal: Core Operations, Map Structure, and Practical Examples
JD Tech Talk
JD Tech Talk
Dec 27, 2024 · Backend Development

Log Sampling and Cross‑Thread Propagation in High‑Throughput Java Services

The article examines the performance impact of excessive logging in large‑scale Java systems and proposes request‑level sampling with cross‑thread identifier propagation, offering practical component‑based solutions, implementation considerations, and a concrete code example for backend developers.

BackendJavaThreadLocal
0 likes · 7 min read
Log Sampling and Cross‑Thread Propagation in High‑Throughput Java Services
JD Cloud Developers
JD Cloud Developers
Dec 27, 2024 · Backend Development

How to Implement Cross-Thread Log Sampling in High-Throughput Java Services

Log volume can cripple high-throughput Java systems, especially during traffic spikes, so this article explores practical strategies for request-level log sampling, cross-thread trace propagation, and component-based APIs to balance observability with performance, including code examples and implementation considerations.

JavaThreadLocallog sampling
0 likes · 8 min read
How to Implement Cross-Thread Log Sampling in High-Throughput Java Services
Programmer XiaoFu
Programmer XiaoFu
Dec 12, 2024 · Backend Development

4 Elegant Ways to Transfer Data Between Async Threads in Spring Boot

The article compares four techniques—manual ThreadLocal copying, TaskDecorator, InheritableThreadLocal, and Alibaba's TransmittableThreadLocal—for passing user context and other data from parent to child threads in Spring Boot async execution, recommending the TaskDecorator and TransmittableThreadLocal approaches for production use.

@AsyncConcurrencyJava
0 likes · 13 min read
4 Elegant Ways to Transfer Data Between Async Threads in Spring Boot
Top Architect
Top Architect
Nov 21, 2024 · Backend Development

Best Practices and Common Pitfalls of Using Thread Pools in Java

This article summarizes how to correctly declare, monitor, configure, and name Java thread pools, explains common mistakes such as unbounded queues and ThreadLocal contamination, and introduces dynamic tuning techniques and open‑source solutions for robust backend concurrency management.

Best PracticesConcurrencyJava
0 likes · 18 min read
Best Practices and Common Pitfalls of Using Thread Pools in Java
Rare Earth Juejin Tech Community
Rare Earth Juejin Tech Community
Oct 28, 2024 · Backend Development

Resolving Missing Request Headers in Spring MVC Multithreaded Environments

This article analyzes why Spring MVC fails to retrieve request header fields in multithreaded scenarios, explains the underlying ThreadLocal storage mechanism, critiques a common but flawed solution, and presents reliable approaches using CountDownLatch, manual RequestContextHolder propagation, and request caching to ensure header availability across threads.

BackendJavaRequestContextHolder
0 likes · 10 min read
Resolving Missing Request Headers in Spring MVC Multithreaded Environments
Mike Chen's Internet Architecture
Mike Chen's Internet Architecture
Aug 4, 2024 · Backend Development

Understanding Java Memory Leaks and How to Prevent Them

This article explains what memory leaks are in Java, outlines common causes such as unreleased resources, static collections, misuse of ThreadLocal, improper variable scope, inner‑class references and off‑heap memory, and provides practical solutions and best‑practice recommendations to avoid them.

Best PracticesJVMJava
0 likes · 9 min read
Understanding Java Memory Leaks and How to Prevent Them
MaGe Linux Operations
MaGe Linux Operations
Jul 25, 2024 · Fundamentals

Unlock Python Multithreading: A Complete Guide to Threads, Locks, and Queues

This article provides a comprehensive overview of Python multithreading, covering basic concepts, the _thread and threading modules, thread creation methods, synchronization primitives like Lock and RLock, thread-local storage, thread pools, and the differences between multithreading and multiprocessing for both CPU‑bound and I/O‑bound workloads.

ConcurrencyLockPython
0 likes · 24 min read
Unlock Python Multithreading: A Complete Guide to Threads, Locks, and Queues
JD Tech Talk
JD Tech Talk
Jul 8, 2024 · Backend Development

Implementing Data Permission Control with MyBatis Interceptor and ThreadLocal

This article explains how to enforce data permission control in Java backend applications by using MyBatis mapper annotations, ThreadLocal rule propagation, and a MyBatis interceptor that parses and rewrites SQL statements with permission constraints, providing minimal intrusion to existing business logic.

Data PermissionMyBatisSQL interceptor
0 likes · 11 min read
Implementing Data Permission Control with MyBatis Interceptor and ThreadLocal
Rare Earth Juejin Tech Community
Rare Earth Juejin Tech Community
Jul 1, 2024 · Backend Development

Resolving Data Contamination in Multithreaded Security Testing by Redesigning Class Attributes in Python

This article explains how using a shared class attribute to store open ports in a Python security‑testing framework can cause data contamination across threads, demonstrates the problem with example code, and presents three solutions—reinitializing the attribute, using contextvars, and employing threading.local—to ensure thread‑local isolation and accurate port scanning.

Class AttributesContextVarPython
0 likes · 10 min read
Resolving Data Contamination in Multithreaded Security Testing by Redesigning Class Attributes in Python
FunTester
FunTester
Jun 4, 2024 · Backend Development

Why FastThreadLocal Beats ThreadLocal in High‑Concurrency Java Apps

This article compares Java's standard ThreadLocal with Netty's FastThreadLocal, explains their internal mechanisms, shows practical code examples, runs a JMH microbenchmark, and discusses performance, memory management, and usage scenarios to help developers choose the right thread‑local storage solution.

ConcurrencyFastThreadLocalJMH
0 likes · 11 min read
Why FastThreadLocal Beats ThreadLocal in High‑Concurrency Java Apps
Code Ape Tech Column
Code Ape Tech Column
May 4, 2024 · Backend Development

Understanding PageHelper Pagination Issues and ThreadLocal Management in MyBatis

This article analyzes common anomalies caused by the PageHelper pagination plugin in a Java backend project—such as duplicate user registration, limited query results, and password‑reset errors—traces them to ThreadLocal misuse, explains the internal workflow of startPage, getLocalPage, and clearPage, and offers practical recommendations to avoid these pitfalls.

BackendJavaMyBatis
0 likes · 11 min read
Understanding PageHelper Pagination Issues and ThreadLocal Management in MyBatis
Su San Talks Tech
Su San Talks Tech
Apr 30, 2024 · Backend Development

Mastering Context Propagation in Thread Pools with TransmittableThreadLocal

This article explains why standard ThreadLocal mechanisms fail with thread pools, introduces the design of a custom solution using YesThreadLocal and YesRunnable, and then details how Alibaba's TransmittableThreadLocal (TTL) implements context capture, replay, and restoration for seamless asynchronous execution.

ConcurrencyContextPropagationJava
0 likes · 12 min read
Mastering Context Propagation in Thread Pools with TransmittableThreadLocal
Architect
Architect
Apr 23, 2024 · Backend Development

Cross-Thread Log Sampling for High-Throughput Java Services

This article examines the performance impact of excessive logging in high-throughput Java services and presents three practical approaches—ThreadLocal-style wrappers, explicit flag propagation, and a decoupled component with an extensible API—to achieve cross-thread request-level log sampling while preserving traceability.

BackendJavaThreadLocal
0 likes · 9 min read
Cross-Thread Log Sampling for High-Throughput Java Services
Java Captain
Java Captain
Mar 25, 2024 · Fundamentals

Understanding Java ThreadLocal: Mechanism, Use Cases, and Best Practices

ThreadLocal in Java provides thread‑local variables by maintaining a per‑thread map, enabling data isolation, simplifying inter‑thread data transfer, and storing context information, while requiring careful handling to avoid memory leaks, thread‑pool contamination, and overuse.

Best PracticesConcurrencyJava
0 likes · 5 min read
Understanding Java ThreadLocal: Mechanism, Use Cases, and Best Practices
Architect's Guide
Architect's Guide
Mar 15, 2024 · Backend Development

Implementing Dynamic Data Source Switching in Spring Boot with ThreadLocal and AbstractRoutingDataSource

This tutorial demonstrates how to build a custom dynamic data source solution in Spring Boot by combining ThreadLocal and AbstractRoutingDataSource, covering the implementation of context holders, routing logic, configuration, testing, annotation‑driven switching, and runtime addition of new data sources.

DynamicDataSourceJavaSpringBoot
0 likes · 16 min read
Implementing Dynamic Data Source Switching in Spring Boot with ThreadLocal and AbstractRoutingDataSource
FunTester
FunTester
Feb 18, 2024 · Backend Development

Mastering Java Concurrency: Threads, Synchronization, and Immutable Design

This article provides a step‑by‑step guide to Java concurrency, covering core concepts such as threads, runnables, thread lifecycle, synchronization primitives, wait/notify patterns, volatile variables, ThreadLocal storage, and how to design immutable objects for thread‑safety, all illustrated with concrete code examples and detailed explanations.

ConcurrencyImmutableJava
0 likes · 17 min read
Mastering Java Concurrency: Threads, Synchronization, and Immutable Design
Java Tech Enthusiast
Java Tech Enthusiast
Feb 9, 2024 · Backend Development

Understanding PageHelper Issues and ThreadLocal in MyBatis Pagination

Unexpected duplicate registrations, truncated query results, and password‑reset SQL errors in a Java backend were traced to PageHelper’s ThreadLocal pagination state persisting across requests when startPage() is called without immediate query execution, so developers should ensure immediate execution or manually clear the ThreadLocal to prevent stale LIMIT clauses.

JavaMyBatisThreadLocal
0 likes · 12 min read
Understanding PageHelper Issues and ThreadLocal in MyBatis Pagination
Java Architect Essentials
Java Architect Essentials
Jan 18, 2024 · Backend Development

Implement Dynamic Data Source Switching in Spring Boot with ThreadLocal and AbstractRoutingDataSource

This tutorial explains how to switch between multiple databases in a Spring Boot application by implementing ThreadLocal and AbstractRoutingDataSource, covering code implementation, configuration, testing, annotation-based switching, and dynamic addition of data sources with detailed examples and practical guidance.

DynamicDataSourceJavaMyBatis-Plus
0 likes · 15 min read
Implement Dynamic Data Source Switching in Spring Boot with ThreadLocal and AbstractRoutingDataSource
IT Niuke
IT Niuke
Jan 8, 2024 · Backend Development

How to Gracefully Switch Data Sources Dynamically in a SpringBoot Project

This article walks through implementing dynamic data‑source switching in SpringBoot by combining ThreadLocal with AbstractRoutingDataSource, covering manual code, configuration, annotation‑driven AOP, and runtime addition of new data sources, complete with test cases and sample code.

AOPAbstractRoutingDataSourceMyBatis-Plus
0 likes · 17 min read
How to Gracefully Switch Data Sources Dynamically in a SpringBoot Project
Architect
Architect
Dec 18, 2023 · Backend Development

Implementing Dynamic Data Source Switching in Spring Boot with ThreadLocal and AbstractRoutingDataSource

This article demonstrates how to build a custom dynamic data‑source solution for Spring Boot by using ThreadLocal to store the current datasource key, extending AbstractRoutingDataSource for routing, configuring multiple datasources in application.yml, and optionally adding annotation‑driven switching and runtime datasource registration.

AbstractRoutingDataSourceDynamicDataSourceJava
0 likes · 15 min read
Implementing Dynamic Data Source Switching in Spring Boot with ThreadLocal and AbstractRoutingDataSource
Java High-Performance Architecture
Java High-Performance Architecture
Dec 14, 2023 · Backend Development

Master Dynamic Data Source Switching with ThreadLocal in SpringBoot

This guide explains how to implement dynamic data source switching in SpringBoot by leveraging ThreadLocal and AbstractRoutingDataSource, covering basic concepts, code examples for context holder, routing datasource, configuration, annotation‑driven switching, and runtime addition of new data sources with practical testing steps.

Dynamic Data SourceJavaMyBatis-Plus
0 likes · 18 min read
Master Dynamic Data Source Switching with ThreadLocal in SpringBoot
IT Xianyu
IT Xianyu
Dec 12, 2023 · Backend Development

Implementing Dynamic Data Source Switching in Spring Boot Using ThreadLocal and AbstractRoutingDataSource

This article explains how to build a custom dynamic data‑source solution for Spring Boot by leveraging ThreadLocal and AbstractRoutingDataSource, provides complete Java code for context holders, routing datasource, configuration, annotation‑driven switching, and runtime addition of new data sources.

AbstractRoutingDataSourceBackendMyBatis-Plus
0 likes · 15 min read
Implementing Dynamic Data Source Switching in Spring Boot Using ThreadLocal and AbstractRoutingDataSource
Selected Java Interview Questions
Selected Java Interview Questions
Nov 22, 2023 · Backend Development

Thread Pool Pitfalls and Best Practices in Java Backend Development

This article analyzes a real production incident caused by improper thread‑pool usage, explains common misconceptions about core parameters, demonstrates faulty code examples, and provides concrete recommendations for configuring thread pools, handling timeouts, and avoiding deadlocks in Java backend services.

CompletableFutureJava concurrencySpring Async
0 likes · 14 min read
Thread Pool Pitfalls and Best Practices in Java Backend Development