- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 27.3k
Open
Description
Description
Thread-Specific Storage is a concurrency design pattern where each thread retains its own instance of a shared object, typically achieved using ThreadLocal<T> in Java. By isolating data to each thread, you avoid synchronization overhead and minimize concurrency issues. Common use cases include storing thread-specific contexts, caching stateful objects like DateFormat, or managing per-thread counters without risking data corruption or race conditions.
Key Elements
- Isolation of State: Each thread has its own copy of the data, reducing shared mutable state.
- ThreadLocal Utility: Java’s
ThreadLocal<T>class provides a straightforward way to store data private to each thread. - Initialization & Cleanup: Properly initializing and cleaning up thread-local data is crucial to prevent memory leaks.
- Practical Use Cases: Storing per-thread data such as locale-specific formatters, current transaction context, or local caches.
References
- Pattern-Oriented Software Architecture, Volume 2: Patterns for Concurrent and Networked Objects
- Java Design Patterns - Contribution Guidelines
Acceptance Criteria
- A new module or package named
thread-specific-storage(or similar) is added.Demonstrates a clear use case of storing and retrieving thread-local data (e.g., per-thread state).Includes a readme (or.mdfile) explaining how the pattern works, with code examples or diagrams.Adheres to the repository’s coding style and naming conventions.Includes unit tests verifying behavior in a multi-threaded scenario.Passes all CI checks and meets the project’s contribution guidelines.To pick up a draggable item, press the space bar. While dragging, use the arrow keys to move the item. Press space again to drop the item in its new position, or press escape to cancel.
Metadata
Metadata
Assignees
Projects
Status
Todo
Milestone
Relationships
Development
Select code repository
Activity
CMD137 commentedon May 31, 2025
Hello @iluwatar .I would like to work on this .Could you assign it to me? It would be a great opportunity to learn!
MFrikken commentedon Jul 6, 2025
Hey @iluwatar, I'm currently working on a thread-safety related topic in Java and am craving for some hands on practice. Feel free to assign me for this issue so I can start right away!
CMD137 commentedon Sep 26, 2025
If there’s no objection, I’ll start implementing this now and submit a PR. 🚀
RitikaMathur19 commentedon Oct 15, 2025
Is someone working on this already , No one is assigned yet. Else please assign it to me.
kdt523 commentedon Oct 17, 2025
Hi, I’d like to work on this issue . Could you please assign it to me?
quantambites commentedon Oct 22, 2025
doing it .