my dog learned polymorphism
The moose likes Beginning Java and the fly likes Volatile Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Volatile" Watch "Volatile" New topic


Hari babu
Ranch Hand

Joined: Jun 25, 2001
Posts: 208
Hi all,
Volatile is used for a variable which can be modified asynchronously. How can modify a variable asynchronously?
Please help
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 986

This modifier is used to identify a variable which can be modifed by different threads. So 'volatile' is suppose to tell the compiler to not perform certain optimizations on the variable.
So for example: you make two instances of ThreadClassA. In ThreadClassA there is a variable named 'VolatileTemp'. Each instance of TheadClassA can than change 'VolatileTemp' at will.
Did that answer your question in anyway?

Please ignore post, I have no idea what I am talking about.
I agree. Here's the link:
subject: Volatile
It's not a secret anymore!