Square CSS

Saturday, November 17, 2018

Java Multithreading : Volatile Key (Basic Synchronization)

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.

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 :






                    Executor Service is an interface in Java to create a pool of the ... 

No comments:

Post a Comment

Some Algorithms

Algorithm: Tower of Hanoi

Tower of Hanoi consists of three towers called as pegs with n number of rings. Rings are of different size.  Conditions to be fulfill...

Popular Posts