Monday, 16 January 2017

What is Thread Local ?

Thread Local
Thread Local can be considered as a scope of access, like a request scope or session scope. It's a thread scope. You can set any object in Thread Local and this object will be global and local to the specific thread which is accessing this object

     Values stored in Thread Local are global to the thread, meaning that they can be accessed from anywhere inside that thread. If a thread calls methods from several classes, then all the methods can see the Thread Local variable set by other methods (because they are executing in same thread)

     Values stored in Thread Local are local to the thread, meaning that each thread will have its own Thread Local variable. One thread cannot access/modify other thread's Thread Local variables.

     ThreadLocal in Java is a different way to achieve thread-safety, it doesn't address synchronization requirement, instead it eliminates sharing by providing explicitly copy of Object to each thread


     ThreadLocal are visible only in Single Thread. No two Thread can see each other’s ThreadLocal variable

No comments:

Post a Comment