InterviewSolution
| 1. |
What Is The Purpose Of The Class Java.lang.threadlocal? |
|
Answer» As memory is shared between different threads, THREADLOCAL PROVIDES a way to store and retrieve values for each thread separately. Implementations of ThreadLocal store and retrieve the values for each thread INDEPENDENTLY such that when thread A stores the value A1 and thread B stores the value B1 in the same instance of ThreadLocal, thread A later on retrieves value A1 from this ThreadLocal instance and thread B retrieves value B1. As memory is shared between different threads, ThreadLocal provides a way to store and retrieve values for each thread separately. Implementations of ThreadLocal store and retrieve the values for each thread independently such that when thread A stores the value A1 and thread B stores the value B1 in the same instance of ThreadLocal, thread A later on retrieves value A1 from this ThreadLocal instance and thread B retrieves value B1. |
|