aspose file tools*
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 Java 8 in Action this week in the Java 8 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: 1368
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

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: 36566
    
  16
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
 
Consider Paul's rocket mass heater.
 
subject: Volatile - synchronized ?
 
Similar Threads
volatile keyword
abt variable synchronization
Use of volatile variable with wait() and notify()
wait() help
another thread question