Volatile vs Static in Java

2019-01-01 04:28发布

Is it correct to say that static means one copy of the value for all objects and volatile means one copy of the value for all threads?

Anyway a static variable value is also going to be one value for all threads, then why should we go for volatile?

7条回答
怪性笑人.
2楼-- · 2019-01-01 05:09

I think static and volatile have no relation at all. I suggest you read java tutorial to understand Atomic Access, and why use atomic access, understand what is interleaved, you will find answer.

查看更多
登录 后发表回答