JAVA threads (different stacks) synchronization

后端 未结 8 1603
北恋
北恋 2021-01-05 22:19

I have a question regarding synchronization of code that is executed by several threads:

As far as I know each thread has its own stack, hence, non-static variables

8条回答
  •  南方客
    南方客 (楼主)
    2021-01-05 23:22

    Local variables, primitives and references are implicitly thread-local. However, objects referenced can be shared and when a thread can modify a shared object it is highly likely you will need synchronised, a Lock or some other strategy to ensure thread safety.

提交回复
热议问题