Quick Answer
ThreadLocal gives each thread its own independent variable copy. Changes in one thread don't affect other threads. Common use: per-request context (user session, database connection, locale) in web frameworks. Spring's RequestContextHolder uses ThreadLocal. Important: always remove() when done (especially in thread pools - threads are reused and old values persist, causing bugs and memory leaks).
Answer
ThreadLocal stores per-thread variables. Each thread gets its own isolated copy. Useful for caching, user sessions, or context propagation.
S
SugharaIQ Editorial Team
Verified Answer
This answer has been peer-reviewed by industry experts holding senior engineering roles to ensure technical accuracy and relevance for modern interview standards.