What is the volatile keyword useful for?

前端 未结 23 2653
闹比i
闹比i 2020-11-21 05:32

At work today, I came across the volatile keyword in Java. Not being very familiar with it, I found this explanation.

Given the detail in which that arti

23条回答
  •  太阳男子
    2020-11-21 06:09

    Every thread accessing a volatile field will read its current value before continuing, instead of (potentially) using a cached value.

    Only member variable can be volatile or transient.

提交回复
热议问题