This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Threads and Synchronization and the fly likes Thread local Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Thread local" Watch "Thread local" New topic

Thread local

jacob deiter
Ranch Hand

Joined: Apr 02, 2008
Posts: 580
in which scenario ,Thread local can be used?.please give some real time examplae
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

Right down the bottom of this article, "The benefits of ThreadLocal". It covers scenarios where they are useful.

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Vinod K Singh
Ranch Hand

Joined: Sep 30, 2008
Posts: 198
If you use storage then don't forget to do the cleanup.

My Blog
arulk pillai
Ranch Hand

Joined: May 31, 2007
Posts: 3359
ThreadLocal is a handy class for simplifying development of thread-safe concurrent programs by making the object stored in this class not sharable between threads. ThreadLocal class encapsulates non-thread-safe classes to be safely used in a multi-threaded environment and also allows you to create per-thread-singleton. A typical example would be:

[ September 30, 2008: Message edited by: arulk pillai ]

[] | [Java job hunting know how] | [Java resumes]
jacob deiter
Ranch Hand

Joined: Apr 02, 2008
Posts: 580
Hi Arul

Thank you for your reply.

[ September 30, 2008: Message edited by: jacob deiter ]
[ October 01, 2008: Message edited by: jacob deiter ]
I agree. Here's the link:
subject: Thread local
It's not a secret anymore!