using volatile keyword

后端 未结 6 1563
轮回少年
轮回少年 2020-12-21 02:26

As i understand, if we declare a variable as volatile, then it will not be stored in the local cache. Whenever thread are updating the values, it is updated to the main mem

6条回答
  •  执念已碎
    2020-12-21 02:38

    This has nothing to do with volatile; those are two separate instances of ExampleThread, with their own copies of testValue1 and testValue, which are instance fields (not static class variables, which are "shared" between all instances).

提交回复
热议问题