|
Answer» Below are some key points about ThreadLocal variables
- A thread-local variable EFFECTIVELY provides a separate copy of its value for each thread that uses it.
- ThreadLocal instances are typically private static FIELDS in classes that wish to associate state with a thread
- In case when multiple threads access a ThreadLocal instance, separate copy of Threadlocal variable is MAINTAINED for each thread.
- Common use is seen in DAO pattern where the DAO class can be singleton but the Database connection can be maintained separately for each thread. (PER Thread Singleton)
- ThreadLocal variable are difficult to understand and I have found below reference links very useful in getting BETTER understanding on them
Below are some key points about ThreadLocal variables
|