JAVA threads (different stacks) synchronization

后端 未结 8 1620
北恋
北恋 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:04

    Some key points which can help clarifying your doubts -

    1. Objects are always allocated on heap.

    2. Class level variables are shared across threads (thread of same object )

    3. Local variables are always thread safe (if not exposed to outside world in non thread safe manner)

提交回复
热议问题