This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Need a example for 'volatile' Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Need a example for Watch "Need a example for New topic
Author

Need a example for 'volatile'

jitendra vishnoi
Greenhorn

Joined: Jan 19, 2010
Posts: 10
Hi All,

I need a code example for understanding of volatile keyword. I found some example on net but they are not working on my machine. Is there are any universal example for volatile that can run on all machines with same result.
Thanks in advance.


Jitendra Vishnoi.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Ok, what is the use of volatile?
jitendra vishnoi
Greenhorn

Joined: Jan 19, 2010
Posts: 10
Hi Seetharaman,

Thanks for reply. As per my understanding If a variable is declared as volatile it means when it used by a thread, then thread will go to main memory for getting its value not its local copy of that variable.
jitendra vishnoi
Greenhorn

Joined: Jan 19, 2010
Posts: 10
I got solution for my problem.



If it is not working on your machine just add more new ChangeListener().start(); to make CPU enough busy to force its threads to use local copy of variable.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need a example for 'volatile'