I'm studying the modifiers for class members. I'm having hard time understanding volatile Variables. I read that it is use to inform the compiler that it should not attempt to perform optimizations on the variable. Can anyone give me programming example where this is actually applied? Thanks!
IMHO, When your appz read a variable, he must first access that variable. The JVM make some optimization, it memorize the last value of your variable, so you don't lose time accessing your variable. The problem is if your variable is shared and it's value changed by a thread, and another thread want to read the value of your variable, he (the second thread) won't read the "real-time" value of your variable, but the copy in the JVM (result of the optimization). So if you have a variable that value is often changed by another thread, you may use the Keyword 'Volatile' to tell the JVM "Don't use optimization on this variable" I hope that I was clear! (I know that my english is sh....)
By constantly trying one ends up succeeding. Thus: the more one fails the more one has a chance to succeed.
Joined: Jan 13, 2002
Hi Snigdha, I can't reach your link, could you plz check the url Thx a lot Sorry I found it, here is the good url [ June 20, 2002: Message edited by: Younes Essouabni ]