Compare volatile vs static variables in Java
Compare volatile vs static variables in Java
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.
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.
Đăng nhập để tham gia thảo luận cùng mọi người.
Chưa có bình luận nào
Hãy là người đầu tiên chia sẻ suy nghĩ của bạn.