Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Threads and Synchronization and the fly likes Volatile - synchronized ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Volatile - synchronized ?" Watch "Volatile - synchronized ?" New topic
Author

Volatile - synchronized ?

kri shan
Ranch Hand

Joined: Apr 08, 2004
Posts: 1381
Can i specify volatile variable within synchronized method or synchronized block ? Volatile works only with multithreaded code(non thread-safe) ?
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
volatile is a modifier that only applies for instance and class variables.

It makes that different Threads do not cache the value of the corresponding variable and hence always retrieve the latest, up-to-date, could-have-been-modified-by-another-thread value.


JDBCSupport - An easy to use, light-weight JDBC framework -
Monu Tripathi
Rancher

Joined: Oct 12, 2008
Posts: 1369
    
    1

If you are interested in understanding Synchronization and about volatile modifier and if you have time, consider reading Synchronization and Java Memory Model.


[List of FAQs] | [Android FAQ] | [Samuh Varta]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39478
    
  28
Probably best moved to the threads forum.
Nitish Bangera
Ranch Hand

Joined: Jul 15, 2009
Posts: 537

One thing to note, there is only one non access modifier for local variables and that is final. There are no other non access modifiers for local variables.


[ SCJP 6.0 - 90% ] , JSP, Servlets and Learning EJB.
Try out the programs using a TextEditor. Textpad - Java 6 api
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Volatile - synchronized ?