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

ely (Ely)
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..
2001-2-5 -05:00

回到话题: Jabber's java questions...

回到论坛: HOME枫下论坛枫下论坛主坛工作学习IT技术讨论