• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

When should i use ThreadLocal?

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When should i use ThreadLocal? What would I acheive from that? Is there any scenerios where I should use ThreadLocal?
 
Ranch Hand
Posts: 193
Mac OS X Fedora Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Without using ThreadLocal, each instances of a class is shared among all the threads being provisioned and can easily create some thread issues if that class is not designed as thread safe.

With using ThreadLocal, each thread will create its own instance of that class and isolate that instance from other threads.

When to use:
It is a great utility to use when trying to solve thread issues.
My 2 cents.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Perhaps a better introduction: http://www.ibm.com/developerworks/java/library/j-threads3/index.html
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I hope this will help you
http://www.javamex.com/tutorials/synchronization_concurrency_thread_local3.shtml
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic