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 -04:00
This post has been archived. It cannot be replied.
Page address has been copied. To share, click to copy page address.
Share Online by QR Code

Back To Topic: Jabber's java questions...

Back To Forum: HOME枫下论坛枫下论坛主坛工作学习IT技术讨论