Unlike object-level variables, thread-local variables are variables exclusive to a thread. In a class, the ThreadLocal object is declared as a static private variable.
When a new thread uses a getter or setter to access an object, a copy of the object is accessed.
When a thread uses the get or set methods of a ThreadLocal instance, a new copy is added to the list of objects that it is connected with.
Java Interview Questions with Answers (2023)