What are volatile variables?
A volatile variable is modified asynchronously by concurrently running threads in a Java application.It is not allowed to have a local copy of a variable that is different from the value currently held in “main” memory. Effectively, a variable declared volatile must have it’s data synchronized across all threads, so that whenever you access or update the variable in any thread, all other threads immediately see the same value. Of course, it is likely that volatile variables have a higher access and update overhead than “plain” variables, since the reason threads can have their own copy of data is for better efficiency.
Related Questions
- My firewall starts and restarts fine but if I try shorewall restore, the script fails because none of my shell variables from /etc/shorewall/params are set. Why?
- Why cannot the compiler optimization issues just be side-stepped by declaring the relevant shared variables volatile?
- What are volatile variables?