Tuesday, August 4, 2015

ThreadLocal and Inheritable ThreadLocal


I am not going to share any new concept or library of java. My topic of this post related to ThreadLocal that is with us since JDK version 1.2 but after discussion with many developers with in my circle I came to know that many developer doesn't know it feature and functionality.

Thread Local storage is just like class that can store/return object with in thread scope. Just like application context, session or request scope with in servlet.

Thread-local storage (TLS) is a computer programming method that uses static or global memory local to a thread [wikipedia].

ThreadLocal instances are typically private static fields in classes that usually maintain thread state 

This class is very useful if you want to share common objects into different applications layers like users credentials, connection objects etc. I usually use this class after wrapping it in my ThreadContext class. Following are the code of my ThreadContext class. 

To save my common object with in thread I usually call it's static put method and when I need to use that saved object I call it's static object.  


5 comments:

Unknown said...

Superb i got some valuable tips from here. Really its a amazing article i had ever read. I hope it will help a lot for all. Thank you so much for this amazing posts and please keep update like this excellent article.

Selenium

Unknown said...

Thanks for the good words! Really appreciated. Great post. I ve been commenting a lot on a few blogs recently, but I had nt thought about my approach until you brought it up.

SAP training in Chennai

Unknown said...

Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your blog.
Selenium Training

Unknown said...

Nice article, Thanks for sharing and keep sharing.
upcoming college events | upcoming campus festivals

pixel studios said...

Great post.
Digital Marketing Agency In Chennai
Ecommerce Website Development Company In Chennai