Originally posted by amit sanghai:
Thanks Jim. What is the alternative to stop().
Waht is the function of the "volatile" keyword?
Originally posted by CL Gilbert:
As for the volatile keyword, seems a mistake. I have not yet found an appropriate situation for it....
Why you make long and double exceptions? volatile makes long and double access atomic.
"but it is not very efficient to create synchronized setter and getter methods with a single operation in each." I dont know why you feel this way? Give me an example where volatile works better than synchronization. In the above example it does not. you access to the variable is still unsafe because what if someone tried to stop it even before it was started? or while it was starting? volatile wont protect you.
Originally posted by Henry Wong:
Volatile does not make any variables atomic. Volatile forces the JVM to not make a copy (or cache) of the variable, and to directly access them everytime. Access to long and double variables are not atomic because the specification does not require it.
Not sure what you mean. How do you start or stop a volatile variable?
Access to long and double variables is atomic when associated with the keyword volatile. And this is precisely spelled out in the specification.
I was referring to starting and stopping a thread which is what this forum thread was about.