
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What does the modifier volatile in Java do?
The volatile modifier is used to let the JVM understand that a thread accessing the variable should always merge its own personal copy of the variable with the original in the memory.
Accessing a volatile variable synchronizes all the cached copy of the variables in the main memory. Volatile can only be applied to instance variables, which are of type object or private. A volatile object reference can be null.
Example
public class MyRunnable implements Runnable { private volatile boolean active; public void run() { active = true; while (active) { } } public void stop() { active = false; } }
- Related Questions & Answers
- What does the modifier transient in Java do?
- What does synchronized modifier do in Java?
- What does abstract modifier in Java do?
- What does the volatile keyword mean in C++?
- What does the compareTo do in Java?
- What does the 'b' modifier do when a file is opened using Python?
- What does the 'U' modifier do when a file is opened using Python?
- What does the method trimToSize() do in java?
- What does the method getFirst() do in java?
- What does the method getLast() do in java?
- What does the method removeFirst() do in java?
- What does the method removeLast() do in java?
- What does the method firstElement() do in java?
- What does the method lastElement() do in java?
- What does the method removeAllElements() do in java?
Advertisements