- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
volatile Keyword in Java
The volatile modifier is used to let the JVM know that a thread accessing the variable must always merge its own private copy of the variable with the master copy in the memory.
Accessing a volatile variable synchronizes all the cached copied 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 Articles
- Can we make Array volatile using volatile keyword in Java?
- volatile keyword in C#
- What is volatile keyword in C++?
- What does the volatile keyword mean in C++?
- Difference between volatile and transient in java
- What does the modifier volatile in Java do?
- Volatile Storage vs Non-Volatile Storage
- What are 'Volatile' and 'Non-volatile' substances?
- instanceof Keyword in Java
- Private Keyword in Java
- Protected Keyword in Java
- Public Keyword in Java
- static Keyword in Java
- synchronized Keyword in Java
- transient Keyword in Java

Advertisements