PDA

View Full Version : What is volatile keyword in Java?



sulbha
01-03-2018, 12:25 AM
What is volatile keyword in Java?

swikriti.sharma
01-03-2018, 04:48 AM
The volatile keyword in Java is poorly documented, poorly understood, and rarely used.volatile is used to indicate that a variable's value will be modified by different threads.

jackar56
01-05-2018, 01:52 AM
Volatile variable in Java is a special variable which is used to signal threads, compiler that this particular variables values is going to be updated by multiple thread inside Java application. By making a variable volatile using volatile keyword in Java,application programmer ensures that its value should always been read from main memory and thread should not used cached value of that variable from there own stack.

traveloweb
01-09-2018, 02:37 AM
The value of this variable will never be cached thread-locally: all reads and writes will go straight to "main memory"; Access to the variable acts as though it is enclosed in a synchronized block, synchronized on itself.

gamblerr
02-11-2018, 08:08 AM
As I know Each thread has its own stack, and so its own copy of variables it can access. When the thread is created, it copies the value of all accessible variables in its own memory. The volatile keyword is used to say to the jvm "Warning, this variable may be modified in an other Thread". And remember one thing use penetration testing (https://www.checkmarx.com/glossary/penetration-testing-for-company-security/) so that there will be no vulnerability related errors.

damponting44
09-11-2018, 01:37 AM
The value of this variable will never be cached thread-locally: all reads and writes will go straight to "main memory"; Access to the variable acts as though it is enclosed in a synchronized block, synchronized on itself.

RH-Calvin
09-12-2018, 11:11 PM
Volatile keyword is a qualifier that is applied to a variable when it is declared. It tells the compiler that the value of the variable may change at any time--without any action being taken by the code the compiler finds nearby. A variable should be declared volatile whenever its value could change unexpectedly.

williamhills
10-28-2018, 09:42 PM
The volatile keyword in Java signifies that value of a variable is modified by other threads. This is a poorly understood keyword and used rarely when necessary. Keep in mind that if you are using volatile keyword then it needs to be documented well so that it can be quickly understood by other developers.