Java / Java ThreadLocal
How do I create a ThreadLocal variable?
The below line illustrates the way to create a ThreadLocal Variable.
private ThreadLocal myThrLocalVariable = new ThreadLocal();
Note that the above line of code needs to be executed only once by any thread. Even when multiple threads execute the code that accesses the ThreadLocal variable, each thread will access only the value set in its own copy of ThreadLocal instance. One Thread cannot access the any other thread's value of ThreadLocal variable.
More Related questions...