Static variables and multithreading in java

后端 未结 7 1736
心在旅途
心在旅途 2020-12-02 13:31

Is a static member of a class present as only a single instance per process or thread? Meaning does each thread has its own copy of the static member variable of the class?

7条回答
  •  天涯浪人
    2020-12-02 14:19

    Static fields gave one value per class-loader.

    If you want a per-thread value, make a static ThreadLocal.

提交回复
热议问题