Prev Next

Java / Java ThreadLocal

Difference between ThreadLocal class and volatile keyword in Java.

Both are completely unrelated.

The ThreadLocal class stores a variable in the Thread object of the current running thread, each thread gets its own copy of ThreadLocal instance, the ThreadLocal instances are not shared among the Threads.

Volatile keyword instructs the compiler that this variable be accessed/shared across multiple threads.

More Related questions...

Show more question and Answers...


Comments & Discussions