Quick Refresh : Java : ThreadLocal and InheritableThreadLocal
Quick Refresh : Java : ThreadLocal and InheritableThreadLoc al java.lang. ThreadLocal This class provides a thread-local variable. These variables differ from their normal counterparts in that each thread that accesses one (via its get or set method) has its own, independently initialized copy of the variable. Basically, it is another way to achieve thread-safety apart from writing immutable classes. Since Object is no more shared there is no requirement of Synchronization which can improve scalability and performance of an application. It extends Object class. ThreadLocal provides thread restriction which is an extension of the local variable. ThreadLocal is visible only in a single thread. No two threads can see each other's thread-local variables. These variables are generally private static fields in classes and maintain their state inside a thread. Creating a ThreadLocal Here is a code example that shows how to create a ThreadLocal variable: private...