The concepts of the volatile key are often misunderstood and often explained in the wrong way.
Providing the concepts in simple and in an easy to understand way.
Providing the concepts in simple and in an easy to understand way.
What is volatile Key?
Volatile is a keyword which can be applied to a variable to perform basic synchronization.
To make a variable volatile provide volatile in the declaration of the variable.
Uses of volatile key:
- Used to make operation on a variable like reading and writing through main memory.
- It acts as the operations are performed in a synchronized block.
- The value of a variable will never be caught locally.
Example :
To make use of volatile keyword just provide in the declaration only.
Below is the example where int data variable is used along with the volatile keyword.
public class MyVolatile { private volatile int data = 0; /* other codes along with getter & setter */ } |
Refer the video tutorial :
☛ Next >> Java Multithreading : ExecutorService
Executor Service is an interface in Java to create a pool of the ...
No comments:
Post a Comment