The Artima Developer Community
Sponsored Link

Java Answers Forum
volatile keeps on escaping to me..

1 reply on 1 page. Most recent reply: Apr 25, 2003 8:40 AM by Adam Duffy

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Luka

Posts: 5
Nickname: luka
Registered: Apr, 2003

volatile keeps on escaping to me.. Posted: Apr 25, 2003 6:56 AM
Reply to this message Reply
Advertisement
Dear All,

During my approaching multi-threaded programming, the word volatile has popped up several times.

I should be grateful if you could extol the virtues of such keywork especially with regards to threads.

If happened to stick any details in of how the JVM treats it, well, that would be much appreciated.

Many Thanks

Luca


Adam Duffy

Posts: 168
Nickname: adamduffy
Registered: Feb, 2003

Re: volatile keeps on escaping to me.. Posted: Apr 25, 2003 8:40 AM
Reply to this message Reply
The short answer:

You need to synchronize or make volatile variables holding data that will be shared between threads

The slightly longer and slightly more accurate answer:

The volatile modifier requests the Java VM to always access the shared copy of the variable so the its most current value is always read. If two or more threads access a member variable, AND one or more threads might change that variable's value, AND ALL of the threads do not use synchronization (methods or blocks) to read and/or write the value, then that member variable must be declared volatile to ensure all threads see the changed value.

Adam

Flat View: This topic has 1 reply on 1 page
Topic: java Lexical Scanners Previous Topic   Next Topic Topic: Character Occurrence using arrays

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use