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.  


Dhiya L 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.


Camellia Canan said...

All are saying the same thing repeatedly, but in your blog I had a chance to get some useful and unique information, I love your writing style very much, I would like to suggest your blog in my dude circle, so keep on updates.

SAP training in Chennai

Camellia Canan 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

Jeffy said...

Wow amazing i saw the article with execution models you had posted. It was such informative. Really its a wonderful article. Thank you for sharing and please keep update like this type of article because i want to learn more relevant to this topic.

SEO Company in Chennai

تاریخ اسلام said...


jatin tyagi said...

I have been reading out a lot of your articles.
I will certainly bookmark your Blog.
Free Devops Training
Hybris Training
Dell Boomi Training

Anu Priya 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

Jeffy said...

Thank you for sharing such a nice and interesting blog with us. Hope it might be much useful for us. keep on updating...!!
seo company in india
digital marketing company in india

vini vinitha said...

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

Kale Co Jakim said...

An important building block of SEO is to develop your website which can be easily understandable for both Online Visitors (most important) and search engine robots. In the current digital age, seo is important for your online success means to generate leads.

SEO Services in IndiaSEO Company in India SEO Company in India SEO Services in India