×

Loading...

java.lang.ThreadLocal provides a solution for the dilemma of static and nonstatic fields.

When u declare a static field, there is only one value of the field for all objects, when u declare a non-static instance, every object has its own copy of this variable.. If u declare static filed to hold a ThreadLocal, it can holds a different value for each thread. Objects running in the same thread can get the identical value by calling get() while those running in different threads get different value..
Report

Replies, comments and Discussions: