wood burning stoves 2.0*
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: 576
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: 3219
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 Interview Questions and Answers Blog | Amazon.com profile | Java Interview Books
jacob deiter
Ranch Hand

Joined: Apr 02, 2008
Posts: 576
Hi Arul

Thank you for your reply.

[ September 30, 2008: Message edited by: jacob deiter ]
[ October 01, 2008: Message edited by: jacob deiter ]
subject: Thread local
Similar Threads
Local variables always thread safe ?
Is session object thread safe.
What is thread-local variable
Help w/SingleThreadModel
multiple threads for database