This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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 Murach's Java Servlets and JSP this week in the Servlets 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: 1371
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: 37936
    
  22
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Volatile - synchronized ?
 
Similar Threads
Use of volatile variable with wait() and notify()
another thread question
abt variable synchronization
volatile keyword
wait() help