• Post Reply Bookmark Topic Watch Topic
  • New Topic

When should i use ThreadLocal?

 
rup gupta
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • 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?
 
Jiafan Zhou
Ranch Hand
Posts: 193
Fedora Linux Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps a better introduction: http://www.ibm.com/developerworks/java/library/j-threads3/index.html
 
sean lopez
Greenhorn
Posts: 25
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!