0
Useness of Volatile variables in java
I know how volatile variables work , and the logic of this variables.although i does seen any Usefulness of volatiles in java. Pleas send an example (code) that show how volatiles can solves a problem that could not has been solved without volatiles. (Do not suggest web sites , i readed most of them)
1 Respuesta
+ 1
volatile variable are used in threading concept in java .when a variable is declared volatile it provides that the threads don't create a local cache and it is fetched from the main memory every time the threads access it thus the thread accessing it cannot change the value provides the atomicity.
main(String[] args)
{
volatile long var=1200000L;
var--; //we cant do it throws exception