Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Volatile keyword

 
Lokanadham Nalla
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Could explain what is the use of volatile keyword in java. I have read it many places but I am always confused with it.

Thank you.
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check this.
 
srikanth reddy
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if the variable is declared as volatile then the it means that each thread will have a copy of that variable ......

thanks & regards

srikanth reddy
 
Vlado Zajac
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by srikanth reddy:
if the variable is declared as volatile then the it means that each thread will have a copy of that variable ......

thanks & regards

srikanth reddy


Actually the volatile meaning is oposite. Volatile variable does have only one master copy and threads access it directly.

Non-volatile variables may or may not (depends on JVM) have a private copy for each thread. The private copies are synchronized with the master copy only at certain points.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic