File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 JavaScript Promises Essentials this week in the JavaScript 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'