Volatile keyword in Java | Multithreading in Java [Hindi] | 07

The volatile keyword in Java is used to mark a variable as "being stored in main memory". This means that every read of a volatile variable will be read from the computer's main memory, and not from the CPU registers, and that every write to a volatile variable will be written to main memory, and not just to the CPU registers.
The volatile keyword is used to solve the visibility problem in multithreading. The visibility problem occurs when multiple threads are accessing the same variable, and one thread changes the value of the variable, but the other threads do not see the change. This can happen because the CPU registers of each thread cache the values of the variables, and the changes made by one thread are not immediately reflected in the other threads' registers.
The volatile keyword ensures that all threads see the latest value of a variable, even if the variable is cached in the CPU registers of other threads. This is because the volatile keyword forces the compiler to write the value of the variable to main memory every time it is changed.
The volatile keyword can be used with both primitive and object variables. However, it cannot be used with classes or methods.
----------------------------------------------------------------------------------
volatile keyword in java,
volatile keyword explained,
volatile keyword example,
volatile keyword multithreading,
volatile keyword synchronization,
volatile keyword vs synchronized,
volatile keyword in java interview questions,
volatile keyword tutorial,
volatile keyword in java code,

Пікірлер: 3

  • @FurqanHussain8888
    @FurqanHussain88887 ай бұрын

    very complex topic but your explaination make it easy Thnx Sir for wonderful video

  • @chinmayapradhan412
    @chinmayapradhan4125 ай бұрын

    thank you sir for this amazing explanation

  • @sarangpatel2437
    @sarangpatel24375 ай бұрын

    Hi , need more sessions on multi threading

Келесі