java-design-patterns icon indicating copy to clipboard operation
java-design-patterns copied to clipboard

thread-specific-storage

Open quantambites opened this issue 2 months ago • 3 comments

Pull Request Template

What does this PR do?

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.

#3225

quantambites avatar Oct 22 '25 17:10 quantambites

Analyzing changes in this PR...

This might take a few minutes, please wait

📥 Commits

Analyzing changes from base (ede37bd) to latest commit (57f0388):

📁 Files being considered (8)

🔄 .github/workflows/presubmit.yml (1 hunk) 🔄 pom.xml (1 hunk) ➕ thread-specific-storage/README.md (1 hunk) ➕ thread-specific-storage/etc/seq.png (0 hunks) ➕ thread-specific-storage/pom.xml (1 hunk) ➕ thread-specific-storage/src/main/java/com/iluwatar/threadspecificstorage/App.java (1 hunk) ➕ thread-specific-storage/src/main/java/com/iluwatar/threadspecificstorage/ThreadLocalContext.java (1 hunk) ➕ thread-specific-storage/src/test/java/com/iluwatar/threadspecificstorage/AppTest.java (1 hunk)


autogenerated by presubmit.ai

github-actions[bot] avatar Oct 22 '25 17:10 github-actions[bot]

i dont know why the hell the llm api key is not being taken i have spend much time and reserch in it pls review

quantambites avatar Oct 22 '25 18:10 quantambites

Quality Gate Failed Quality Gate failed

Failed conditions
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

sonarqubecloud[bot] avatar Oct 23 '25 08:10 sonarqubecloud[bot]