TheThreadLocal
class in Java enables you to create variables that can only be read and written by the same thread. Thus, even if two threads are executing the same code, and the code has a reference to aThreadLocal
variable, then the two threads cannot see each other'sThreadLocal
variables.