Compare volatile vs st...
Compare volatile vs st...
In Java, both volatile
and static
are keywords that apply to variables, but they serve very different purposes and have different behaviors.
The volatile
keyword in Java is used to mark a variable as "stored in main memory." Essentially, it means that every read of a volatile variable will be read from the main memory, and not from the CPU cache, and every write to a volatile variable will be written to main memory, and not just to the CPU cache[3][5][7][10].
The static
keyword, on the other hand, is used to indicate that a particular field or method belongs to the class, rather than instances of the class[4][6][11][12].
expert
Gợi ý câu hỏi phỏng vấn
Chưa có bình luận nào