Tagged articles

ThreadLocal

228 articles · Page 3 of 3
Programmer DD
Programmer DD
Apr 22, 2020 · Backend Development

How ThreadLocal Guarantees Thread Isolation and Avoids Memory Leaks in Java

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
How ThreadLocal Guarantees Thread Isolation and Avoids Memory Leaks in Java
FunTester
FunTester
Feb 24, 2020 · Backend Development

Achieving Thread‑Safe Java Performance Tests Without Locks

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

ConcurrencyJavaLock-Free
0 likes · 5 min read
Achieving Thread‑Safe Java Performance Tests Without Locks
Architect's Tech Stack
Architect's Tech Stack
Feb 14, 2020 · Backend Development

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

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

Memory LeakThread SafetyThreadLocal
0 likes · 7 min read
Understanding ThreadLocal Variables in Java: Implementation, Memory Leak Issues, and Use Cases
AI Code to Success
AI Code to Success
Jan 11, 2020 · Mobile Development

Why Does Creating a Handler in a Background Thread Throw an Exception?

This article explains Android's Handler and Looper mechanism, shows why creating a Handler in a non‑Looper thread triggers a RuntimeException, and walks through the relevant source code—including Handler constructors, Looper.myLooper(), ThreadLocal operations, and the required Looper.prepare() call.

ANRAndroidConcurrency
0 likes · 10 min read
Why Does Creating a Handler in a Background Thread Throw an Exception?
Programmer DD
Programmer DD
Dec 15, 2019 · Backend Development

Java ThreadLocal Deep Dive: Structure, 0x61c88647 Hash Trick & Usage

This article explains the internal architecture of Java's ThreadLocal, including its ThreadLocalMap implementation, the purpose of the special hash code 0x61c88647, collision handling strategies, proper usage patterns in web applications, and precautions for avoiding memory leaks in thread pools.

ConcurrencyJavaMemoryLeak
0 likes · 12 min read
Java ThreadLocal Deep Dive: Structure, 0x61c88647 Hash Trick & Usage
Java Backend Technology
Java Backend Technology
Nov 28, 2019 · Backend Development

How to Prevent ThreadLocal Memory Leaks in Java: Causes and Solutions

This article explains why improper use of ThreadLocal can lead to memory leaks in Java, details the underlying weak‑reference mechanism, and provides practical steps—including explicit removal and Spring integration—to safely manage ThreadLocal data and avoid resource exhaustion.

ConcurrencyJavaMemory Leak
0 likes · 7 min read
How to Prevent ThreadLocal Memory Leaks in Java: Causes and Solutions
Java Architecture Diary
Java Architecture Diary
Nov 2, 2019 · Backend Development

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

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

SimpleDateFormatThread SafetyThreadLocal
0 likes · 7 min read
Why SimpleDateFormat Is Not Thread‑Safe and How to Fix It Efficiently
Amap Tech
Amap Tech
Oct 23, 2019 · Fundamentals

Java Programming Techniques: Collections, ThreadLocal, Pair, Enum, Union, and Generics

The article presents a toolbox of practical Java techniques—including using HashSet for fast duplicate detection, HashMap for building hierarchical structures, ThreadLocal for thread‑specific data, Pair and custom holder classes for multiple return values, enum definitions, union‑style classes, and generic and wildcard patterns—to streamline everyday coding tasks.

EnumsJavaThreadLocal
0 likes · 22 min read
Java Programming Techniques: Collections, ThreadLocal, Pair, Enum, Union, and Generics
Python Crawling & Data Mining
Python Crawling & Data Mining
Oct 21, 2019 · Fundamentals

Why Python Threads Can’t Fully Utilize Multi‑Core CPUs and How to Use Them Effectively

This tutorial explains Python's multithreading model, its advantages and limitations—including the Global Interpreter Lock—demonstrates thread creation with the threading module, shows race conditions and lock usage, compares processes and threads, and discusses when to choose threads, processes, or asynchronous I/O for different workloads.

GILLockPython
0 likes · 17 min read
Why Python Threads Can’t Fully Utilize Multi‑Core CPUs and How to Use Them Effectively
Tech Musings
Tech Musings
Oct 20, 2019 · Backend Development

How Netty Supercharges ThreadLocal with FastThreadLocal – Inside the Code

This article dissects Netty's custom FastThreadLocal and FastThreadLocalThread implementations, showing how they replace JDK ThreadLocal with constant‑time indexed access, padding to avoid false sharing, and customizable initialization and cleanup to boost backend concurrency performance.

ConcurrencyFastThreadLocalNetty
0 likes · 16 min read
How Netty Supercharges ThreadLocal with FastThreadLocal – Inside the Code
Programmer DD
Programmer DD
Sep 5, 2019 · Fundamentals

Understanding ThreadLocal: Solving Thread Safety Issues in Java

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

InheritableThreadLocalJavaThread Safety
0 likes · 9 min read
Understanding ThreadLocal: Solving Thread Safety Issues in Java
Java Backend Technology
Java Backend Technology
Jul 26, 2019 · Backend Development

Mastering ThreadLocal: When, How, and Best Practices in Java

This article explains the purpose and usage scenarios of Java's ThreadLocal, details its two main functions for storing thread context and ensuring thread safety, discusses garbage‑collection nuances, presents sample code with results, and outlines essential best‑practice guidelines for safe multithreaded development.

ConcurrencyJavaMemory Leak
0 likes · 8 min read
Mastering ThreadLocal: When, How, and Best Practices in Java
dbaplus Community
dbaplus Community
Jun 16, 2019 · Fundamentals

Understanding Thread Safety: From ThreadLocal to Locks and CAS

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

CASJava concurrencyLocks
0 likes · 15 min read
Understanding Thread Safety: From ThreadLocal to Locks and CAS
Programmer DD
Programmer DD
May 12, 2019 · Backend Development

Why SimpleDateFormat Breaks in Multithreaded Java and How to Fix It

This article explains why the classic Java SimpleDateFormat class is not thread‑safe, demonstrates the problems caused by using a static instance in concurrent code, and presents four practical solutions—including creating new instances, synchronizing, using ThreadLocal, and switching to the immutable DateTimeFormatter.

DateTimeFormatterJavaSimpleDateFormat
0 likes · 8 min read
Why SimpleDateFormat Breaks in Multithreaded Java and How to Fix It
Java Backend Technology
Java Backend Technology
Mar 19, 2019 · Backend Development

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

This article explains why Java's SimpleDateFormat is not thread‑safe, demonstrates the problems caused by using a static instance in multithreaded code, and presents four practical solutions—including synchronized blocks, ThreadLocal, and the modern DateTimeFormatter—to ensure correct date handling.

DateTimeFormatterJavaSimpleDateFormat
0 likes · 5 min read
Why SimpleDateFormat Is Not Thread‑Safe and How to Fix It in Java
Programmer DD
Programmer DD
Nov 13, 2018 · Backend Development

How to Detect and Prevent Java Memory Leaks: Real‑World Examples and Fixes

This tutorial explains what Java memory leaks are, why they occur, and how to identify them at runtime, covering common leak sources such as static fields, unclosed resources, faulty equals/hashCode implementations, inner classes, finalize methods, string interning, and ThreadLocal misuse, plus practical prevention techniques and profiling tools.

Best PracticesGarbage CollectionJava
0 likes · 15 min read
How to Detect and Prevent Java Memory Leaks: Real‑World Examples and Fixes
转转QA
转转QA
Sep 20, 2018 · Backend Development

Implementing Dynamic RPC Service Invocation in a Commercial Testing Platform

The article describes how a commercial testing platform faced three limitations with its RPC client, analyzes Java class‑loading, dynamic proxy, and ThreadLocal concepts, and presents two implementation approaches—one using dynamic proxies and another leveraging ThreadLocal—to enable dynamic loading of multiple rpc.config files without restarting the service.

RPCThreadLocaldynamic-proxy
0 likes · 6 min read
Implementing Dynamic RPC Service Invocation in a Commercial Testing Platform
Java Backend Technology
Java Backend Technology
Oct 24, 2017 · Fundamentals

ThreadLocal OOM? Exploring Singleton Pitfalls in Java Multithreading

This article examines common Java singleton implementations—including eager, thread‑safe lazy, double‑checked locking, and static inner‑class approaches—explaining their requirements, potential memory‑leak pitfalls such as ThreadLocal‑induced OOM, and how improper usage in multithreaded environments can lead to unexpected instance creation and performance issues.

ConcurrencyDesign PatternsJava
0 likes · 6 min read
ThreadLocal OOM? Exploring Singleton Pitfalls in Java Multithreading
Java Backend Technology
Java Backend Technology
Sep 27, 2017 · Fundamentals

Unlocking ThreadLocal: How Java Gives Each Thread Its Own Variable

This article explains the purpose of Java's ThreadLocal class, shows a practical example with code and output images, compares it to synchronized locking, and demonstrates how ThreadLocal provides each thread with an independent variable copy for safe concurrent access.

ConcurrencyJavaProgramming Fundamentals
0 likes · 3 min read
Unlocking ThreadLocal: How Java Gives Each Thread Its Own Variable
Java Captain
Java Captain
Jul 24, 2017 · Fundamentals

Lesser‑Known Java Thread Techniques and Usage

This article explores five advanced Java thread topics—including naming, priority, ThreadLocal storage, daemon vs. user threads, and processor affinity—providing code examples, practical tips, and guidance for both beginners and seasoned developers.

DaemonThreadProcessorAffinityThreadLocal
0 likes · 12 min read
Lesser‑Known Java Thread Techniques and Usage
Qunar Tech Salon
Qunar Tech Salon
Apr 6, 2015 · Fundamentals

How to Write Java Code That Causes a Memory Leak

Various techniques for deliberately creating memory leaks in Java are presented, including using long‑running threads with custom class loaders, static references, ThreadLocal misuse, improper handling of resources like connections and streams, and flawed implementations of hashCode/equals, each illustrated with code examples.

JavaMemory LeakStatic Reference
0 likes · 6 min read
How to Write Java Code That Causes a Memory Leak